Gotzboost

I am trying to call an unmanaged DLL within c#. I have the DLLs source so I know what the variables are within C, I just can't seem to build the DLLImport function correctly. Can someone help me out here

The C function
int UULoadFile (char *filename, char *fileid, int delflag)

{
.......
}

The C export
#define _ANSI_ARGS_(c) c
int UULoadFile _ANSI_ARGS_((char *, char *, int));

My DLLImport
internal const String UUDEVIEW = "uudeview.dll";
[
DllImport(UUDEVIEW, EntryPoint = "UULoadFile", SetLastError = true
)]
internal static extern int UULoadFile([MarshalAs(UnmanagedType.LPStr)]string filename, [MarshalAs(UnmanagedType.LPStr)]string fileid, int delflag);

Everytime I call UULoadFile I get,

An unhandled exception of type 'System.AccessViolationException' occurred in NZB Queue.exe

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.



Re: Visual C# General Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

TilakGopi

My DLLImport
internal const String UUDEVIEW = "uudeview.dll";
[
DllImport(UUDEVIEW, EntryPoint = "UULoadFile", SetLastError = true
)]
internal static extern int UULoadFile([MarshalAs(UnmanagedType.LPStr)]string filename, [MarshalAs(UnmanagedType.LPStr)]string fileid, int delflag);

can't it be like this

My DLLImport
internal const String UUDEVIEW = "uudeview.dll";
[
DllImport(UUDEVIEW, EntryPoint = "UULoadFile", SetLastError = true
)]
internal static extern int UULoadFile(string filename,string fileid, int delflag);

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C# General Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Gotzboost

Ok I don't see any difference other than you removing the MarshalAs attribute. And no, it can't, it still causes the same error when calling.



Re: Visual C# General Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Peter Ritchie

Does the UULoadFile function actually modify any of the memory pointed to by filename or fileid




Re: Visual C# General Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Vaughn Friesen

There's a post on DLLs here. Hope it helps you.