Jump to content

Recommended Posts

Posted

Boa noite,

tenho uma dll qye foi desenvolvida em c e estou a tentar utilizá-la em c#.

No entanto dá-me o seguinte erro: "Tentativa de ler ou escrever na memória protegida. Isto é normalmente uma indicação de que existe outra memória danificada."

[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32")]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("lib.dll", EntryPoint = "LoadRes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern SRes LoadRes([MarshalAs(UnmanagedType.LPStr)]string str, bool type);

SRes sres = new SRes();
string path="C:\\123456.fil";
System.IntPtr load = LoadLibrary("lib.dll");
System.IntPtr adress = GetProcAddress(load, "LoadRes");		   
sres = LoadRes(path, true);

E esta é a linha da dll em c.

__declspec(dllexport) SRes  LoadRes( const char *filename, bool header_only );

Muito obrigado pela ajuda!

Posted

Férias! Estou por aqui: http://maps.google.p...001549&t=h&z=20 (a bulir claro está!)

Nunca mais é verão outra vez.. :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.