Calling a vb.net program from C++

I have a vb.net program that I created. I would like to be able to call the functions from that program (vb.net) inside of C++.

How can I do that?
Your VB.NET program must list the functions you wish to call as exportable (so that they are in the EXE's export table). This is a bit tricky in VB.NET (I didn't think it was possible until I found this article):
http://www.codeproject.com/KB/vb-interop/interopvb6netcexporthook.aspx

Usually only DLLs have export tables, but there is no reason an EXE can't have one also and be used as if it were a DLL.

Then, you can use LoadLibrary() to open the executable and GetProcAddress() to get pointers to the functions you wish to call. Make sure to pay attention to the article I linked for you.

The function pointer should be declared with the WINAPI calling convention:
1
2
3
4
typedef WINAPI int (*PMyFunc)( int arg1, char arg2, etc );

HMODULE MyDLL  = LoadLibrary( "foo.net.exe" );
PMyFunc MyFunc = (PMyFunc)GetProcAddress( MyDLL, "MyFunc" );

Also keep in mind that your exported functions should not take fancy object types as arguments or return them -- keep them to things like integers and characters and char* strings and the like.

Hope this helps.
I don't mean to go off-topic, here, but what happens if the DLL was written in C++ (name mangling)?
You have to turn off name mangling for exported functions -- or provide unmangled accessor functions.

But the OP's problem is he wants to use C++ to access functions in a compiled .NET application... (Yoinks!)
closed account (z05DSL3A)
There is also COM/.net interoperability (if you know about COM (Component Object Model)).

Calling a .NET Component from a COM Component
http://msdn.microsoft.com/en-gb/library/ms973802.aspx

Last edited on
Topic archived. No new replies allowed.