Hi!
Your DLL have C++ export, which have decorated function name. You need to export it in C mode, check extern "C" in C++ manuals.
Hi!
Your DLL have C++ export, which have decorated function name. You need to export it in C mode, check extern "C" in C++ manuals.
tet
TranThanh
I have a unmanged .dll that I am currently using within C/C++ just fine...
I wish to use that unmanaged DLL with C#. I am using Microsoft Visual Studio 2005, and I am using C++/CLI using interops.
Currently I having some issues concerning some exceptions. Some methods are working and some methods are not.
Note that the code below are inorder. The same way represented with the real files but alot of useless code taken out which isn't relevant
C/C++ WORKS
within the c/c++ file I have the following... This is my main application for c++. IT should display No error found or error found...
[code]
HDErrorInfo error;
if (HD_DEVICE_ERROR(error = hdGetError())) {
// Display Error
}
else {
// No error found
}
[/code]
Within the header file
[code]
// Some header
#if defined(WIN32)
# ifdef HD_EXPORTS
# define HDAPI __declspec(dllexport)
# else
# define HDAPI __declspec(dllimport)
# endif
# define HDAPIENTRY __stdcall
# define HDCALLBACK __stdcall
#endif /* WIN32 */
// Type Definitions
typedef unsigned int HDerror;
typedef unsigned int HHD;
// Defines
#define HD_SUCCESS 0x0000
#define HD_DEFAULT_DEVICE NULL
// Error Struct
typedef struct
{
HDerror errorCode; /* The HD_ error code */
int internalErrorCode; /* The original internal device-generated error */
HHD hHD; /* The handle of the current device when the error occurred */
} HDErrorInfo;
// Functions
HDAPI HHD HDAPIENTRY hdInitDevice(HDstring pConfigName);
HDAPI HDErrorInfo HDAPIENTRY hdGetError();
// Macros
#define HD_DEVICE_ERROR(X) (((X).errorCode) != HD_SUCCESS)
[/code]
The above code works perfectly within c/c++. It all depends on the hd.dll library. No error and runs fine. So I am wishing to port that code to C#. That is where I am having trouble.
Note that, instead of me including the other 10000 lines of code, I only included the relevent ones
C# DOES NOT WORK
Okay now to my C# code... Which I have done using interops... Note that all the code is in order.
[code]
[StructLayout(LayoutKind.Sequential)]
public struct HDErrorInfo
{
public uint errorCode;
public int internalErrorCode;
public uint hHD;
}
// Constants
public const string HD_DEFAULT_DEVICE = null;
public const uint HD_SUCCESS = 0x0000;
// Lets DLL Import this
[DllImport("hd")]
public static extern uint hdInitDevice(string pConfigName);
[DllImport("hd")]
public static extern HDErrorInfo hdGetError();
// We are not DLL Importing this... Since its a macro...
public static bool HD_DEVICE_ERROR(HDErrorInfo x) { return x.errorCode != HDConstants.HD_SUCCESS; }
[/code]
And the Main calling application looks like this...
[code]
// Initializations
HDDefines.HDErrorInfo error;
// This is another DLL Call which appears to be working.. No ERROR found..
uint hHD = HDDevice.hdInitDevice( HDDefines.HD_DEFAULT_DEVICE);
if (HDDevice.HD_DEVICE_ERROR(error = HDDevice.hdGetError()))
{
MessageBox.Show("Failed to initialize haptic device");
return;
}
else
{
MessageBox.Show("Good to GO!");
return;
}
[/code]
System.EntryPointNotFoundException: Unable to find an entry point named 'hdGetError' in DLL 'hd'.
I used DLL Dependency Walker to check the DLL if it consists that function and it DOES but the name within the dll is as follows:
_hdGetError@0
It is a strange name to see a dll like that. I have been trying for days to get this working... Any ideas on how to troubleshoot it Any help is appreciated! It might be my struct that is causing this I don't know why it says Entry Ppoint not found. I even placed the Ordinal Entry point as well which didn't help.!
I don't know where to turn for help. Thank you
Update:
What do I need to extern Already did that within mine...
Clemens Kolbitsch
rmethod
Cormac
Jalen
[DllImport("hd")]
public static extern HDDefines.HDErrorInfo hdGetError();
I really don't know what to do next ... Any guidance is appreciated. Any extra information you guys need