T
Troy Anderson
How do I execute a dynamically loaded C-API using GetProcAddress in
CompactFramework? I wrote some IL code to do this for full .NET; see the
listing below. This code works on the PC. However, it does not work in
CompactFramework. The library I am loading has been developed with eVC++.
NOTE: I know about P-Invoke but for my application I need to load DLLs and
functions that are specified at runtime (i.e., I do not know the DLL or
function name apriori; I know only the function signature).
Thanks
IL Code:
..assembly extern mscorlib {}
..assembly Canberra.Native {}
..module Canberra.Native.dll
..namespace Canberra.Native.Analysis {
.class public Engine
{
.method public static int32 Invoke(native int Fnc, native int DSC,
unsigned int16 Rec, int32& Arg1, int32& Arg2)
{
ldarg.s 4 // push Arg2
ldarg.2 // push Arg1
ldarg.2 // push Rec
ldarg.1 // push DSC
ldarg.0 // push Fnc
calli unmanaged stdcall int32(native int, int16, int32&, int32&)
ret
}
}
}
Client Code: (Note: LibraryServices is a wrapper over Win32 APIs in order
to run code on either PC or device)
using(LibraryServices LS = new LibraryServices())
{
uint Stat = (uint) LS.LoadLibrary(m_EngineResource);
IntPtr EnginePtr = LS.GetProcAddress(m_EngineEntryPoint);
//Invoke the engine
Stat = (uint) Canberra.Native.Analysis.Engine.Invoke(EnginePtr, Handle,
(ushort) Record, ref Arg1, ref Arg2);
}
CompactFramework? I wrote some IL code to do this for full .NET; see the
listing below. This code works on the PC. However, it does not work in
CompactFramework. The library I am loading has been developed with eVC++.
NOTE: I know about P-Invoke but for my application I need to load DLLs and
functions that are specified at runtime (i.e., I do not know the DLL or
function name apriori; I know only the function signature).
Thanks
IL Code:
..assembly extern mscorlib {}
..assembly Canberra.Native {}
..module Canberra.Native.dll
..namespace Canberra.Native.Analysis {
.class public Engine
{
.method public static int32 Invoke(native int Fnc, native int DSC,
unsigned int16 Rec, int32& Arg1, int32& Arg2)
{
ldarg.s 4 // push Arg2
ldarg.2 // push Arg1
ldarg.2 // push Rec
ldarg.1 // push DSC
ldarg.0 // push Fnc
calli unmanaged stdcall int32(native int, int16, int32&, int32&)
ret
}
}
}
Client Code: (Note: LibraryServices is a wrapper over Win32 APIs in order
to run code on either PC or device)
using(LibraryServices LS = new LibraryServices())
{
uint Stat = (uint) LS.LoadLibrary(m_EngineResource);
IntPtr EnginePtr = LS.GetProcAddress(m_EngineEntryPoint);
//Invoke the engine
Stat = (uint) Canberra.Native.Analysis.Engine.Invoke(EnginePtr, Handle,
(ushort) Record, ref Arg1, ref Arg2);
}