Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I've posted on here several times and gotten nothing but great advice, so I once again return with my most recent C++/CLI headache.

First, I have some native code, which I wrapped in a C++/CLI library, and the result was MyLib.dll. I've gotten this working very well with C#, but would like to produce some example code in VC++ and VB, and can't seem to figure out how to get those two working.

I could compile the C# program using:
$ csc /nologo /platform:x86 TestProgram.cs /r:MyLib.dll

I know pretty much nothing about VB and don't really know what's different between VC++ and regular C++. What I'm looking for are instructions on what I need to do to convince a VC++ program and a VB program to talk to MyLib.dll. Much of what I found on the internet either looked dated, or mandated the presence of .lib files.

Long story short, what steps need to be taken to call functions defined in a C++/CLI .dll from VC++ and VB code? Any and all advice is very much appreciated!
Posted

1 solution

Shadowsoal wrote:
looking for are instructions on what I need to do to convince a VC++ program and a VB program to talk to MyLib.dll.


MyLib.dll is a mixed mode DLL (compiled using /clr switch), right?

Communicating with a mixed mode DLL from native code is tough. I guess, you need to use conditional compilation and expose the interfaces for managed and unmanaged clients depending upon the compiler options. _MANAGED is a macro which will be defined when /clr compilation switch is used. Make use of this macro to decide the functions you need to expose to native clients. You need to provide a header file as well for native clients as they can't read from the assembly meta data.

I haven't tried the above, but I believe it should do the trick.

:)

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900