Re: Late binding with unmanaged code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



hello,

My Apologies i ommited a number of import calls, was too busy drinking my
morning brew.

[DllImport("kernel32")]
public extern static IntPtr LoadLibrary(string lpLibFileName);

[DllImport("kernel32")]
public extern static Int32 FreeLibrary(IntPtr hModule);

I cant off the top of my head remember where GetProcAadress comes from, i
think it is Kernal32.

I wonder can someone else show an example of importing GetProcAddress

Regards
Scott Blood
C# Developer


"Entwickler" <Entwickler@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:76757E11-EB5B-4194-A5DD-9CA1524E84B9@xxxxxxxxxxxxxxxx
Hello scott,
thank you for your reply. i am trying to apply the code you send but it is
looking like i am missing a namespace . when i try to compile i become the
following errors :
"The name 'LoadLibrary' does not exist in the current context"
"The name 'GetProcAddress' does not exist in the current context"

i am using the following namespaces :
using System.Reflection.Emit;
using System.Reflection;
using System.Runtime.InteropServices;
I don't know if i am missing a namespace .
thanks.



"scott blood" wrote:

Hello,

Unfortunatly you cannot call unmanaged code using late binding in this
method.

Please review the following code which should help you

[DllImport("Invoke", CharSet=CharSet.Unicode)]
public extern static int InvokeFunc(int funcptr, int hwnd, string
message,
string title, int flags);

int hmod=LoadLibrary("MyLib.dll");
int funcaddr=GetProcAddress(hmod, "MyFunction");
int result=InvokeFunc(funcaddr, 0, "Hello World", ".test", 1);
FreeLibrary(hmod);

Regards

Scott Blood
C# Developer

"Entwickler" <Entwickler@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3611B442-44D6-4AFF-9E25-A0C8415B0413@xxxxxxxxxxxxxxxx
hello,
i have the following problem. i want to write a code that enables the
user
to call functions from a unmanaged code .dll at running time . so i
have
to
use the late binding . i tried the following code but it doesn't walk :
Assembly assemblyInstance =
Assembly.LoadFrom(@"C:\myData\UnmanagedCode.dll");
i don't know if somebody can help me .
Regards,





.



Relevant Pages

  • Re: New to C++ entirely (HELP!)
    ... MFC and ATL are C++ class libraries that target native Win32 development. ... int __stdcall WinMain ... using namespace System::IO; ... static void Main2; ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Personal project, extending Scheme to OOP
    ... I've been passing around a reference to a single namespace ... unsigned int type: 4; ...
    (comp.lang.scheme)
  • [PATCH 2/8] ns: Introduce the setns syscall
    ... of containers but in the context of people doing interesting ... There is also demand in the context of containers to have ... int setns; ... an the name of the namespace you think you are changing, ...
    (Linux-Kernel)
  • Re: Q: Why is my BitBlt destination always blank?
    ... the dest bitmap is written to the file system. ... using namespace System; ...
    (microsoft.public.win32.programmer.gdi)
  • Re: (dll) __stdcall functions and GetProcAddress
    ... I have a very simple dll that exports a simple function "int Add ... from an executable using LoadLibrary and GetProcAddress. ... how can I dynamically address stdcall functions from .dll's ... functions generally use stdcall calling convention and we can address those functions dynamically ...
    (microsoft.public.vc.language)