B
ba.hons
Hi all,
Am wondering if anyone can help.
I have received a C++ none COM DLL that i must use to interact to a
peice of hardware. As I am more confident in C# I decided to create a
wrapper for the DLL. As i have found out this is not possible for MS
visual studio to do this automatically from a COM object i created a
C# DLL project to act as a wrapper for the C++ DLL.
Unfortunetly i was quite silly and created all methods in the wrapper
before testing that i could create an instance of my wrapper and the
dll would work.
Now the weird thing is lets say i have a method called init() in the C+
+ code, i have created a method like this in my c# code
public void Init()
{
//set to -1 so that we dont return succuss message by default
int x=-1;
try
{
Process p = Process.GetCurrentProcess();
IntPtr HWND = p.MainWindowHandle;
x = MyWrapper.Initialization();
if(x==0)
{
System.Console.WriteLine(x.ToString());
}
else
{
System.Console.WriteLine(x.ToString());
throw new Exception(x.ToString());
}
}
//an exception occured so return appropriate error message
catch(Exception ex)
{
System.Console.WriteLine(x.ToString());
throw new Exception(ex.Message);
}
}
Now these methods sometimes seem to work in my test application were i
create an instance of my wrapper and call the methods like this:
MYWrapper test = new MyWrapper();
test.MYInitialization()
BUT sometimes they dont seem to work, also i have noticed that if i
add the DLL imports to the top of my test application like this:
[DllImport("Vertx.dll", SetLastError = true, CharSet =
CharSet.Ansi)]
static extern int Initialization(int Port, int HWND, int HINSTANCE);
the methods seem to work more often? even though i never actually call
this method!
Am sorry if i have jumped around a bit but i think i have burnt out my
brain trying to understand what is wrong here.
Also the parameters for the init method in the C++ DLL are:
int Initialization ( int port , HWND hWnd , HINSTANCE hInst )
and i am using:
4070, HWND.ToInt32(),moduleHandle.ToInt32()
in the C# code, am not sure these are correct equivilents.
Any help would be REALLY apprecaited!
Thanks,
Adam
Am wondering if anyone can help.
I have received a C++ none COM DLL that i must use to interact to a
peice of hardware. As I am more confident in C# I decided to create a
wrapper for the DLL. As i have found out this is not possible for MS
visual studio to do this automatically from a COM object i created a
C# DLL project to act as a wrapper for the C++ DLL.
Unfortunetly i was quite silly and created all methods in the wrapper
before testing that i could create an instance of my wrapper and the
dll would work.
Now the weird thing is lets say i have a method called init() in the C+
+ code, i have created a method like this in my c# code
public void Init()
{
//set to -1 so that we dont return succuss message by default
int x=-1;
try
{
Process p = Process.GetCurrentProcess();
IntPtr HWND = p.MainWindowHandle;
x = MyWrapper.Initialization();
if(x==0)
{
System.Console.WriteLine(x.ToString());
}
else
{
System.Console.WriteLine(x.ToString());
throw new Exception(x.ToString());
}
}
//an exception occured so return appropriate error message
catch(Exception ex)
{
System.Console.WriteLine(x.ToString());
throw new Exception(ex.Message);
}
}
Now these methods sometimes seem to work in my test application were i
create an instance of my wrapper and call the methods like this:
MYWrapper test = new MyWrapper();
test.MYInitialization()
BUT sometimes they dont seem to work, also i have noticed that if i
add the DLL imports to the top of my test application like this:
[DllImport("Vertx.dll", SetLastError = true, CharSet =
CharSet.Ansi)]
static extern int Initialization(int Port, int HWND, int HINSTANCE);
the methods seem to work more often? even though i never actually call
this method!
Am sorry if i have jumped around a bit but i think i have burnt out my
brain trying to understand what is wrong here.
Also the parameters for the init method in the C++ DLL are:
int Initialization ( int port , HWND hWnd , HINSTANCE hInst )
and i am using:
4070, HWND.ToInt32(),moduleHandle.ToInt32()
in the C# code, am not sure these are correct equivilents.
Any help would be REALLY apprecaited!
Thanks,
Adam