I'm trying to call a 3rd party vendor's C DLL from vb.net 2005 and am getting P/Invoke
errors. I'm successfully calling other methods but have hit a bottle-neck on one of the more complex. The structures involved are horrendous and in an attempt to simplify the troubleshooting I'd like to create a C++ DLL to replicate the problem.
Can somebody provide the smallest code snippet for a C++ DLL that can be called from .Net? I'm getting a Unable to find entry point named XXX in DLL
error in my C++ dll. It should be simple to resolve but I'm not a C++ programmer.
I'd like to use a .net declaration for the DLL of
Declare Function Multiply Lib "C:\MyDll\Debug\MyDLL.DLL" Alias "Multiply" (ByVal ParOne As Integer, ByVal byvalParTwo As Integer) As Integer
Try using the __decspec(dllexport) magic pixie dust in your C++ function declaration. This declaration sets up several things that you need to successfully export a function from a DLL. You may also need to use WINAPI or something similar:
The WINAPI sets up the function calling convention such that it's suitable for calling from a language such as VB.NET.
Using Greg's suggestion I found the following works. As mentioned I'm not a C++ programmer but just needed something practical.
myclass.cpp #include "stdafx.h"
myclass.def LIBRARY myclass
stdafx.cpp #include "stdafx.h"
stdafx.h
You can try to look at the exported functions (through DumpBin or Dependency Walker) and see if the names are mangled.