Microsoft
Software
Hardware
Network
Question : exception with dllimport
Hello experts
I am having problems with importing a unmanaged dll,
I am getting an exception when trying to run a function that receives a struct (DB_Client).
this is the code,
I am using c# WinForm VS2005
Thanks.
c++ dll :
typedef char FieldStr[256];
typedef char FieldTime[20];
struct DB_Client
{
unsigned long client_id;
unsigned long parent_id;
FieldStr mask_name;
FieldStr comp_name;
FieldStr comp_type;
FieldStr ip;
FieldStr login_name;
FieldStr rdxrc_addr;
FieldStr net_name;
FieldStr os;
FieldTime diff_time;
FieldStr mac_address;
FieldTime handshake_time;
unsigned int is_online;
};
bool DB_get_client(unsigned long client_id, DB_Client& client_obj);
//////////////////////////
//////////
//
c# app
public struct DB_Client
{
public ulong client_id;
public ulong parent_id;
public string mask_name;
public string comp_name;
public string comp_type;
public string ip;
public string login_name;
public string rdxrc_addr;
public string net_name;
public string os;
public string diff_time;
public string mac_address;
public string handshake_time;
public uint is_online;
};
[DllImport("rdxDB.dll")]
public static extern bool DB_get_client(ulong client_id,DB_Client client_obj);
private void form1_Load(object sender, EventArgs e)
{
DB_Client dbcl = new DB_Client();
DBDll.DB_get_client(14,dbc
l);
}
exception:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Answer : exception with dllimport
Did you change the method to use 'ref'
And you've got a long in there - so the C# version needs to have an int instead...
Random Solutions
AJAX Refresh in IE?
Milliseconds
OptiPlex 745 issues
How can we solve the issue of password never expires is unchecked and i want to reset password from the clients itself for users who do not login to the machine.
How to create conditional Data Validation lists in Excel?
Microsoft, Terminal Server, Server 2003 Enterprise, Group Policy Folder Redirection
For Vahik
Use drop shadows for icon labels on the desktop does not work. How do I make My icons on my desktop with Transparen background?
Domain Local,Global and Universal groups in Windows 2003
Rails rake db:create causing error