• Welcome to Valhalla Legends Archive.
 

[vb.net]importing c++ dll

Started by mentalCo., November 03, 2004, 05:10 PM

Previous topic - Next topic

mentalCo.

how do you use a c++ dll in vb.net?  ive been googling for like an hour and a half and havent really figured it out.  maybe im just dumb.  i need an example or something i guess or a link to a tutorial or just some place to start.

MyndFyre

Quote from: mentalCo. on November 03, 2004, 05:10 PM
how do you use a c++ dll in vb.net?  ive been googling for like an hour and a half and havent really figured it out.  maybe im just dumb.  i need an example or something i guess or a link to a tutorial or just some place to start.

Depends on whether or not the C++ is managed or not.  If it *is* managed, then you import it as just another library and have access to any types and functions marked as __gc in the DLL.  If it is not managed, then you import it as a standard C DLL; you can use the Public Declare syntax.  You cannot access C++ classes if they are not managed.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

mentalCo.

#2
ok i got it imported and declared.  now its saying "Unable to find an entry point named Test in DLL UGBDLL.dll."  'Test' is my exported function.

edit: diregard what i said lol. 

ok i made my managed c++ dll:


namespace UGBDLL
{
public __gc class Functions{
public:
int Test(char * crap);
};
}


now i go to my vb.net project and do 'add reference' and add my dll to my project as a COM reference.  Now how do i access my dll in vb.net?

edit:
I got it imported via "imports UGBDLL"
i have access to the class "Functions."  How do i call "Test()"?

edit 2:
ok I got it working now lol thanks.

MyndFyre

Quote from: mentalCo. on November 04, 2004, 02:22 AM
ok i got it imported and declared.  now its saying "Unable to find an entry point named Test in DLL UGBDLL.dll."  'Test' is my exported function.

edit: diregard what i said lol. 

ok i made my managed c++ dll:


namespace UGBDLL
{
public __gc class Functions{
public:
int Test(char * crap);
};
}


now i go to my vb.net project and do 'add reference' and add my dll to my project as a COM reference.  Now how do i access my dll in vb.net?

Why would you add it as a COM reference?  COM is unmanaged.  When you make it managed, that means that you make it available to .NET.  You would add it as a .NET reference.

Also, you should have:

namespace UGBDLL
{
public __gc class Functions{
public:
__gc System::Int32 Test(System::String *crap);
};
}


That gets rid of any ambiguity in types when working across languages.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

mentalCo.

ok i have a new problem.  heres my class in the dll:


namespace UGBDLL
{
public __gc class Functions{
public:
String* Get_0x51(String *mpqname, String *hashcmd, unsigned long encryptvalue, String *cdkey, String* strProduct);
};
}


and heres the definition of Get_0x51():


String* UGBDLL::Functions::Get_0x51(String *mpqname, String *hashcmd, unsigned long encryptvalue, String *cdkey, String* strProduct){
return "test";
}


ok how do i manipulate the arguments.  like mpqname, hashcmd, etc.  i basically want to pass those values off to a different function to be handled.  for example:



void Test(string *strmpqname){
strmpqname += "123";
}

String* UGBDLL::Functions::Get_0x51(String *mpqname, String *hashcmd, unsigned long encryptvalue, String *cdkey, String* strProduct){
                Test(mpqname);
return "test";
}

MyndFyre

Quote from: mentalCo. on November 04, 2004, 03:34 PM
ok how do i manipulate the arguments.  like mpqname, hashcmd, etc.  i basically want to pass those values off to a different function to be handled. 

um....  You pass them....
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

mentalCo.

#6
lol.

i mean like have Test() modify the variables.  take this for example:


void Modify(String *strString){
strString +="123";
}

String* UGBDLL::Functions::Test(String *data){
Modify(data);
return data;
}


I get the error:
error C2845: '+=' : cannot perform pointer arithmetic on __gc pointer 'System::String __gc *'

i read that you need an object to convert between managed and unmanaged pointers or something like that.  i didnt get it and got lost instantly.

edit: ok if i could get an example of a way to copy the contents of "data" into a char array then id be set.

MyndFyre

Quote from: mentalCo. on November 04, 2004, 06:10 PM
lol.

i mean like have Test() modify the variables.  take this for example:


void Modify(String *strString){
strString +="123";
}

String* UGBDLL::Functions::Test(String *data){
Modify(data);
return data;
}


I get the error:
error C2845: '+=' : cannot perform pointer arithmetic on __gc pointer 'System::String __gc *'

i read that you need an object to convert between managed and unmanaged pointers or something like that.  i didnt get it and got lost instantly.

edit: ok if i could get an example of a way to copy the contents of "data" into a char array then id be set.


Learn the language.  In order to use the += operator, you have to dereference the variable.  When you += to a string, it thinks you want to add a string to a pointer, which is illegal.  You need to dereference:


(System::String)(*strString) += "123";


Again: why are you trying to do it this way instead of just going through normal imports of C functions?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

mentalCo.

Quote
Again: why are you trying to do it this way instead of just going through normal imports of C functions?

I was just getting an understandning I guess.  I think I got it now.  But dont be surprised to hear from me in the near future lol.  thanks.

MyndFyre

Quote from: mentalCo. on November 04, 2004, 09:32 PM
Quote
Again: why are you trying to do it this way instead of just going through normal imports of C functions?

I was just getting an understandning I guess.  I think I got it now.  But dont be surprised to hear from me in the near future lol.  thanks.

Learn the language first, please.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

mentalCo.

Im in the middle of failing an intorduction to vb.net class right now lol.