m00
June 19th, 2006, 09:10 PM
Hi, 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 functions are working and somefunctions 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...
HDErrorInfo error;
if (HD_DEVICE_ERROR(error = hdGetError())) {
// Display Error
}
else {
// No error found
}
Within the header file
// 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
// 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 HDErrorInfo HDAPIENTRY hdGetError();
// Macros
#define HD_DEVICE_ERROR(X) (((X).errorCode) != HD_SUCCESS)
The above code works perfectly within c/c++. It all depends on the hd.dll library. No error and runs fine. I am wishing to port it to c#.
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...
[StructLayout(LayoutKind.Sequential)]
public struct HDErrorInfo
{
public uint errorCode;
public int internalErrorCode;
public uint hHD;
}
// Constants
public const uint HD_SUCCESS = 0x0000;
// Lets DLL Import this
[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; }
And the Main calling application...
// Initializations
HapticDevice.HDErrorInfo error;
// This is another DLL Call which appears to be working.. No ERROR found..
uint hHD = HapticDevice.hdInitDevice( HapticDevice.HD_DEFAULT_DEVICE);
if (HapticDevice.HD_DEVICE_ERROR(error = HapticDevice.hdGetError()))
{
MessageBox.Show("Failed to initialize haptic device");
return;
}
else
{
MessageBox.Show("Good to GO!");
return;
}
Now my ERROR is the Following
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
Strange name to see a dLL like that.
I have been trying for days to get this working... Any ideas on how to trouble shoot 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.!
The attached is the complete API for HD (Haptics API for the device) Virtual Reality :)
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 functions are working and somefunctions 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...
HDErrorInfo error;
if (HD_DEVICE_ERROR(error = hdGetError())) {
// Display Error
}
else {
// No error found
}
Within the header file
// 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
// 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 HDErrorInfo HDAPIENTRY hdGetError();
// Macros
#define HD_DEVICE_ERROR(X) (((X).errorCode) != HD_SUCCESS)
The above code works perfectly within c/c++. It all depends on the hd.dll library. No error and runs fine. I am wishing to port it to c#.
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...
[StructLayout(LayoutKind.Sequential)]
public struct HDErrorInfo
{
public uint errorCode;
public int internalErrorCode;
public uint hHD;
}
// Constants
public const uint HD_SUCCESS = 0x0000;
// Lets DLL Import this
[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; }
And the Main calling application...
// Initializations
HapticDevice.HDErrorInfo error;
// This is another DLL Call which appears to be working.. No ERROR found..
uint hHD = HapticDevice.hdInitDevice( HapticDevice.HD_DEFAULT_DEVICE);
if (HapticDevice.HD_DEVICE_ERROR(error = HapticDevice.hdGetError()))
{
MessageBox.Show("Failed to initialize haptic device");
return;
}
else
{
MessageBox.Show("Good to GO!");
return;
}
Now my ERROR is the Following
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
Strange name to see a dLL like that.
I have been trying for days to get this working... Any ideas on how to trouble shoot 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.!
The attached is the complete API for HD (Haptics API for the device) Virtual Reality :)