Attempted to read or write protected memory. This is often an indication that other memory has been

  • Thread starter Thread starter Dick van der Sar
  • Start date Start date
D

Dick van der Sar

I access a dll via dllimport (see below). It workes fine at framework
version 1.1 but now I try to run it in the Beta 1 of VS 2005 and I get
this error message. I have only this problem if a use this function in
a web project.
If I make a standard windows program: no problem.

[DllImport("special.dll", CallingConvention = CallingConvention.Cdecl
)]
private static extern void specialfunction(string name, ....);

Remark:

If I use it in a web project I have to access it via a thread, strange
but it workes.


Has someone an idea?

Dick van der Sar
 
Dick van der Sar said:
I access a dll via dllimport (see below). It workes fine at framework
version 1.1 but now I try to run it in the Beta 1 of VS 2005 and I get
this error message. I have only this problem if a use this function in
a web project.
If I make a standard windows program: no problem.

[DllImport("special.dll", CallingConvention = CallingConvention.Cdecl
)]
private static extern void specialfunction(string name, ....);

Remark:

If I use it in a web project I have to access it via a thread, strange
but it workes.


Has someone an idea?

Dick van der Sar


Please post the whole DllImport function declaration and the C function
export declaration.
Make sure the calling convention is cdecl. Point is that you are passing a
wrong pointer or that are messing with the stack, what would explain why it
works from a separate thread.

Willy.
 
Ok:

private void opendb()
{
ConnectServerAndOpenDatabase("NDBCN", "NAVISIONSERVER", "tcp", "" ,
8000, true, false, "dick", "");
}

[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void DBL_ConnectServerAndOpenDatabase(string
NDBCDriverName, string ServerName, string NetType,
string DatabaseName, int CacheSize, bool UseCommitCache, bool
UseNTAuthentication, string UserID, string PassWord);

public void ConnectServerAndOpenDatabase(string NDBCDriverName, string
ServerName, string NetType,
string DatabaseName, int CacheSize, bool UseCommitCache, bool
UseNTAuthentication, string UserID, string PassWord)
{
DBL_ConnectServerAndOpenDatabase(NDBCDriverName, ServerName, NetType,
DatabaseName, CacheSize, UseCommitCache, UseNTAuthentication, UserID,
PassWord);
}


Willy: Can you also explain that you understand "what would explain why
it works from a separate thread."?

Dick
 
dick van der sar said:
Ok:

private void opendb()
{
ConnectServerAndOpenDatabase("NDBCN", "NAVISIONSERVER", "tcp", "" ,
8000, true, false, "dick", "");
}

[DllImport("cfront.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void DBL_ConnectServerAndOpenDatabase(string
NDBCDriverName, string ServerName, string NetType,
string DatabaseName, int CacheSize, bool UseCommitCache, bool
UseNTAuthentication, string UserID, string PassWord);

public void ConnectServerAndOpenDatabase(string NDBCDriverName, string
ServerName, string NetType,
string DatabaseName, int CacheSize, bool UseCommitCache, bool
UseNTAuthentication, string UserID, string PassWord)
{
DBL_ConnectServerAndOpenDatabase(NDBCDriverName, ServerName, NetType,
DatabaseName, CacheSize, UseCommitCache, UseNTAuthentication, UserID,
PassWord);
}


Willy: Can you also explain that you understand "what would explain why
it works from a separate thread."?

Dick

Dick,

This is good but not yet enough, we need the C function declaration too,
preferably from the header file or from the documentation. Most notably we
need to know what is expected as string and bool.

When you run just this ... ConnectServerAndOpenDatabase on a separate
thread, it might work even if you corrupt the stack, each thread has his own
stack, so when the thread proc returns it's stack is removed anyway.

Willy.
 
Back
Top