Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Calling c# dll in VB 6


Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2006, 10:50 AM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default Calling c# dll in VB 6


PLease Need help, I need to call a dll made in c#.. Hope you can give me a way to do this..

I tried a code in VB, I registered the dll of c# thenrefence the dll.

In my code, I put:

Dim testdll as nameobject

set testdll = new nameobject

then I called and set values to property of the nameobject. But when I run the project, It gives me an error of Missing namespace..
Reply With Quote
  #2  
Old 07-04-2006, 11:51 AM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

Hello, and welcome to the forum :-)

Not every DLL can be directly imported into VB. Did you write the DLL? Are you sure it CAN be imported?
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #3  
Old 07-04-2006, 12:29 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

THanks for the reply.. The dll is created in c#.. Can i give me steps to register a c# dll?? i tried the regsvr32 "Dll name" and it didnt work.. Hope you can help me.. I really need to fix it.. Thanks
Reply With Quote
  #4  
Old 07-04-2006, 12:39 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

it is not just a matter of registering it, the DLL its self has to be capable of being registered and imported into vb. did you write the DLL?


check out http://support.microsoft.com/kb/106553/EN-US/ for a further explanation.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...

Last edited by PrOpHeT; 07-04-2006 at 12:45 PM.
Reply With Quote
  #5  
Old 07-04-2006, 12:43 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

No. how could i know if it can be registered and imported to vb?

can u give me instruction or ideas on how would i know??
Reply With Quote
  #6  
Old 07-04-2006, 12:46 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

Sorry. apparently you were reading while I was editing, see the link in my last post.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #7  
Old 07-04-2006, 12:52 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

can u give me steps on how to unregister dll? when i click the reference in VB it turns that I have 2 dll(the name of my dll) in the reference.. can u please give me instruction to unregister and remove the 2 dll?? thanks alot
Reply With Quote
  #8  
Old 07-04-2006, 12:58 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

if the dll CAn be registered use regsvr.exe

Register:
regsvr32.exe {path and name of dll}

unregister:
regsvr32.exe /u {path and name of dll}

as for using the dll, if you did not write it, and know it CAN be used in vb, you need to know the function names, the parameters they take, and the return data type so you can properly declare them.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #9  
Old 07-04-2006, 01:30 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

dll was loaded, BUt the DllRegisterServer entry point was not found. The file cannot be registered.. Thats the error whenever I will try to register the dll... :-( The same error when i tried to unregister the dll... Do you have any idea why it gives an error like that??
Reply With Quote
  #10  
Old 07-04-2006, 02:14 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

It is not so much an error as an explanation. it means the dll cannot be registered. Again, did you write the dll? Did you look at the link I gave you? If you did not write it, what is it?
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #11  
Old 07-04-2006, 02:35 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

I read the links that you gve me, but I apologized but its not clear to me right now..

I have the code of the c# dll.. When i build the c# project it creates a dll in a given folder.. so what would I do now to be able to use that c# dll??
Reply With Quote
  #12  
Old 07-04-2006, 02:47 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

In my c# dll, I have 4 projects in it, and each project contains subclasses.

project 1: subproj1
myclass1
myclass2

project 2: subproj2

project 3: subproj3

project 4: subproj4


when I complie my project, it creates myGeneric.dll


Can u please give me a way to be able to used it in my VB project??So that I could used the one of the projects in my dll..
Reply With Quote
  #13  
Old 07-04-2006, 02:50 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

The link was an answer to that question, step by step including sample code. What exactly isn't clear? Is there something in there that you do not understand? If so I could possibly explaing a section in more detail, but it pretty much covers it.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #14  
Old 07-04-2006, 03:03 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

Your link explains this:

Declare Sub getdiskinfo Lib "c:\dllartic\diskinfo.dll"

(ByVal mydrive As String, ByVal myvolume As String, free As Long)

where will I put this code?
How about the parameters? what will be the values that I'm going to put in if I will use my dll?

Thanks
Reply With Quote
  #15  
Old 07-04-2006, 03:14 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

I tried it in VB but it gives me an error, runtime 453 'cannot find dll entry point..

can you give me reason why I get that kind of error.. Thanks
Reply With Quote
  #16  
Old 07-04-2006, 03:15 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

That is the import statement for your dll

Private Sub YourSubName Lib "c:\PathToYourDLL\YourDll.Dll" (ByVal WhateverArgumentsYourDllSubTakes)

you declare them at form level in the declarations section, or public in a module.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #17  
Old 07-04-2006, 03:25 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

That is why I posted the above link, there are two sides to the coin, one is the correct use of the dll in VB, the other is that the dll is created to allow vb to use it. Since I know nothing of the DLL's internal workings or the declaration you are using I do not know what else to tell you.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
  #18  
Old 07-04-2006, 03:32 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

Quote:
Originally Posted by PrOpHeT
That is the import statement for your dll

Private Sub YourSubName Lib "c:\PathToYourDLL\YourDll.Dll" (ByVal WhateverArgumentsYourDllSubTakes)

you declare them at form level in the declarations section, or public in a module.
for example I have the name of dll is Main.dll

there are 4 sub projects:

proj1
proj2
proj3
proj4

then proj1 has 3 classes...

The first class gets 2 fields to get the name of filed and the second is the value of the field.

The next class will save the first class...

so can u please give me idea on how am i gonna do that? please... please... Im so hopeless now..
Reply With Quote
  #19  
Old 07-04-2006, 03:37 PM
darchangel_124 darchangel_124 is offline
Freshman
 
Join Date: Jul 2006
Posts: 28
Default

Prophet, is there a way that i could make the dll to be like we usually do in vb, Like Dim mydll as mydllname

set mydll = new mydllname

Thanks
Reply With Quote
  #20  
Old 07-04-2006, 04:04 PM
PrOpHeT's Avatar
PrOpHeT PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,054
Default

Yes if you expose the dll to com and create a wrapper you could delare it as a new instance in the vb and skip the api import.
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->