Exporting __stdcall Functions from VB.NET

MRTrevorF
MRTrevorF used Ask the Experts™
on
I have been asked to write a DLL that exports functions through __stdcall.  I'd really like to do this using Visual Basic.NET (2010 currently) as that is my preferred programming environment.

I've spent quite a long time searching for samples on how to do this, but every hit I found was about the opposite direction - how to call __stdcall C/C++ functions within VB.NET

I'm writing a DLL that will be used by an existing piece of software and they have outlined a series of functions that I must 'export' from my DLL.  I've got sample code in C++, but, again, am hoping to make something in VB.NET.

In C++ the function looks like this:

LONG __stdcall XT_Init(DWORD nVersion, DWORD nFlags, HANDLE hMainWnd, void* lpReserved)

Open in new window


I need to know how to make an equivalent of this in VB.NET.

I've created a Class Library project and added a "COM Class" item to it.

I'm hoping this is posible but am apparently clueless.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
This is an interesting question.  

I did some research into this and the common consensus seems to be that this is not possible in VB.NET - there is no "__stdcall" equivalent.  I looked at http://bytes.com/topic/visual-basic-net/answers/564900-export-function-vb-net-dll (which you have probably also seen): this is just one example of many that form this consensus.

If you already have the C++ code I personally would not try and re-invent the wheel; build the C++ DLL and then call it from your VB.NET app.  (Once a DLL is built, nobody really cares what language it was written in as long as its functionality can be exposed.)  Your time would be best spent implementing your app.

There are enough people who know C++ on this site who can guide you through the DLL creation and any bugs that may arise in the function, so don't worry about that :)

HTH
Most Valuable Expert 2012
Top Expert 2014
Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial