Discussion:
Problem Loading a DLL
(too old to reply)
Fábio Chicout
2010-02-05 13:29:47 UTC
Permalink
I'm having some issues now that I can't see what I'm doing wrong.

I'm Pinvoking a non WindowsAPI-DLL (I mean, not a dll provided on windows).
Pinvoking LoadLibrary, I can get a IntPtr to any WindowsAPI-DLL, but never I
can get a pointer to my DLL.

The code I'm using is very simple, like this one:

[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LoadLibrary();

static void Main(string[] args){
IntPtr libPtr = LoadLibrary(<path to the dll>);
Console.WriteLine(libPtr);
}

This code is only to test if the library was read. When calling
Marshal.GetLastWin32Error(), i got the error 126. I've googled, but found
nothing more than this link:

http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx

Any Ideas?
xcal
2010-02-05 18:53:17 UTC
Permalink
I think your dll have Net code, the CLR has inside its own
mechanism to load net dll code, although I have seen that these
mechanisms use the LoadLibrary function, today I think the whole
steps to accomplish the job are hidden, and that LoadLibrary
simply doesn't work for normal users.

Instead I have seen also, I am almost shure it is possible
to load net libraries at run time try find something in google
at msdn links

hope this helps
Carlos.
Post by Fábio Chicout
I'm having some issues now that I can't see what I'm doing wrong.
I'm Pinvoking a non WindowsAPI-DLL (I mean, not a dll provided on
windows). Pinvoking LoadLibrary, I can get a IntPtr to any WindowsAPI-DLL,
but never I can get a pointer to my DLL.
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LoadLibrary();
static void Main(string[] args){
IntPtr libPtr = LoadLibrary(<path to the dll>);
Console.WriteLine(libPtr);
}
This code is only to test if the library was read. When calling
Marshal.GetLastWin32Error(), i got the error 126. I've googled, but found
http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx
Any Ideas?
xcal
2010-02-05 18:59:27 UTC
Permalink
the problem seems to be easy, but remember that the CLR
have to watch all memory management, wich is not a trivial thing at all,

hope this helps,
Carlos.
Post by xcal
I think your dll have Net code, the CLR has inside its own
mechanism to load net dll code, although I have seen that these
mechanisms use the LoadLibrary function, today I think the whole
steps to accomplish the job are hidden, and that LoadLibrary
simply doesn't work for normal users.
Instead I have seen also, I am almost shure it is possible
to load net libraries at run time try find something in google
at msdn links
hope this helps
Carlos.
Post by Fábio Chicout
I'm having some issues now that I can't see what I'm doing wrong.
I'm Pinvoking a non WindowsAPI-DLL (I mean, not a dll provided on
windows). Pinvoking LoadLibrary, I can get a IntPtr to any
WindowsAPI-DLL, but never I can get a pointer to my DLL.
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LoadLibrary();
static void Main(string[] args){
IntPtr libPtr = LoadLibrary(<path to the dll>);
Console.WriteLine(libPtr);
}
This code is only to test if the library was read. When calling
Marshal.GetLastWin32Error(), i got the error 126. I've googled, but found
http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx
Any Ideas?
Fábio Chicout
2010-02-06 00:58:57 UTC
Permalink
Well, I've done a new test and it worked: I've compiled the native dll
again, but on the computer I was developing the C# project. With the
recompilation, all went right!

Thanks!
Post by xcal
the problem seems to be easy, but remember that the CLR
have to watch all memory management, wich is not a trivial thing at all,
hope this helps,
Carlos.
Post by xcal
I think your dll have Net code, the CLR has inside its own
mechanism to load net dll code, although I have seen that these
mechanisms use the LoadLibrary function, today I think the whole
steps to accomplish the job are hidden, and that LoadLibrary
simply doesn't work for normal users.
Instead I have seen also, I am almost shure it is possible
to load net libraries at run time try find something in google
at msdn links
hope this helps
Carlos.
Post by Fábio Chicout
I'm having some issues now that I can't see what I'm doing wrong.
I'm Pinvoking a non WindowsAPI-DLL (I mean, not a dll provided on
windows). Pinvoking LoadLibrary, I can get a IntPtr to any
WindowsAPI-DLL, but never I can get a pointer to my DLL.
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr LoadLibrary();
static void Main(string[] args){
IntPtr libPtr = LoadLibrary(<path to the dll>);
Console.WriteLine(libPtr);
}
This code is only to test if the library was read. When calling
Marshal.GetLastWin32Error(), i got the error 126. I've googled, but
http://msdn.microsoft.com/en-us/library/ms681382%28VS.85%29.aspx
Any Ideas?
Loading...