Dynamic Invoke from Umanaged Dll in CompactFramework (WinCE 5, C#, VS 2003)

M

Marco [Stinger]

Hi
Sorry if this has been asked before but I'm VERY new to the
compact framework.

Here's my problem
I'm writing a program for a WinCE.NET 5 device using Visual Studio 2003
and C#.
This program needs to call a few DLL writen in EmbeddedC++.
I already know that the dll's work since I've tested them with

[DllImport("Name of the Dll")]
extern static int NameOfTheDllFunction( ...parameters ... );

Unfotunately NOT all the DLLs will be installed (they work like plugins).
So I need to choose dynamically the name(s) of the dll I will be calling.
THe idea is that my app must not know the name of the DLLs
All DLLs have the same functions with the same parameters and return type.

I searched the net for some answers but I'm having a hard time.
Look at

www.codeprojects.com/useritems/dynamicinvokedll.asp

That seems like a solution (even thou I think I need to do something
SIMPLER)
but the namespace System.Reflection.Emit seems to be missing from the
compact framework

Any help will be highly appreciated (free coffee if you come to Milan ;) )

Ciao
Marco
 
M

Marco [Stinger]

Thanks for the hint but I DO NOT NEED to implement
a callback, just call a few functions !!

Ciao
Marco


Sergey Bogdanov said:
As start point see Alex Feinman's article "Implementing call backs in
Compact Framework":
http://www.alexfeinman.com/Callbacks/Callbacks.htm

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi
Sorry if this has been asked before but I'm VERY new to the
compact framework.

Here's my problem
I'm writing a program for a WinCE.NET 5 device using Visual Studio 2003
and C#.
This program needs to call a few DLL writen in EmbeddedC++.
I already know that the dll's work since I've tested them with

[DllImport("Name of the Dll")]
extern static int NameOfTheDllFunction( ...parameters ... );

Unfotunately NOT all the DLLs will be installed (they work like plugins).
So I need to choose dynamically the name(s) of the dll I will be calling.
THe idea is that my app must not know the name of the DLLs
All DLLs have the same functions with the same parameters and return
type.

I searched the net for some answers but I'm having a hard time.
Look at

www.codeprojects.com/useritems/dynamicinvokedll.asp

That seems like a solution (even thou I think I need to do something
SIMPLER)
but the namespace System.Reflection.Emit seems to be missing from the
compact framework

Any help will be highly appreciated (free coffee if you come to Milan
;) )

Ciao
Marco
 
S

Sergey Bogdanov

Let see. To call dynamically function from DLL you should be able to:

1. LoadLibrary
2. GetProcAddresss
3. Call Function by address
4. FreeLibrary

Items 1, 2, 4 could be accomplished using P/Invoke service. But the
problem arises with item 3. It is impossible to call a native function
by address from managed code in the CF1.0. That is why i suggested you
to see this article and also take a look at the last paragraph.

By the way, Full Framework 1.1 allows to pass a pointer to a managed
function to a native function but you can not specify that a value which
returned from native code should be treated as delegate. For Full
Framework 2.0 situation was changed - there is a new method
System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer
that obtains a delegate for any unmanaged function pointer.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Thanks for the hint but I DO NOT NEED to implement
a callback, just call a few functions !!

Ciao
Marco


As start point see Alex Feinman's article "Implementing call backs in
Compact Framework":
http://www.alexfeinman.com/Callbacks/Callbacks.htm

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi
Sorry if this has been asked before but I'm VERY new to the
compact framework.

Here's my problem
I'm writing a program for a WinCE.NET 5 device using Visual Studio 2003
and C#.
This program needs to call a few DLL writen in EmbeddedC++.
I already know that the dll's work since I've tested them with

[DllImport("Name of the Dll")]
extern static int NameOfTheDllFunction( ...parameters ... );

Unfotunately NOT all the DLLs will be installed (they work like plugins).
So I need to choose dynamically the name(s) of the dll I will be calling.
THe idea is that my app must not know the name of the DLLs
All DLLs have the same functions with the same parameters and return
type.

I searched the net for some answers but I'm having a hard time.
Look at

www.codeprojects.com/useritems/dynamicinvokedll.asp

That seems like a solution (even thou I think I need to do something
SIMPLER)
but the namespace System.Reflection.Emit seems to be missing from the
compact framework

Any help will be highly appreciated (free coffee if you come to Milan
;) )

Ciao
Marco
 
G

Guest

Declare all of the P/Invokes, then wrap them with shell calls that have a
try...catch. If the try fails due to a MissingMethodException, then the DLL
isn't present.

-Chris


Marco said:
Thanks for the hint but I DO NOT NEED to implement
a callback, just call a few functions !!

Ciao
Marco


Sergey Bogdanov said:
As start point see Alex Feinman's article "Implementing call backs in
Compact Framework":
http://www.alexfeinman.com/Callbacks/Callbacks.htm

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com

Hi
Sorry if this has been asked before but I'm VERY new to the
compact framework.

Here's my problem
I'm writing a program for a WinCE.NET 5 device using Visual Studio 2003
and C#.
This program needs to call a few DLL writen in EmbeddedC++.
I already know that the dll's work since I've tested them with

[DllImport("Name of the Dll")]
extern static int NameOfTheDllFunction( ...parameters ... );

Unfotunately NOT all the DLLs will be installed (they work like
plugins).
So I need to choose dynamically the name(s) of the dll I will be
calling.
THe idea is that my app must not know the name of the DLLs
All DLLs have the same functions with the same parameters and return
type.

I searched the net for some answers but I'm having a hard time.
Look at

www.codeprojects.com/useritems/dynamicinvokedll.asp

That seems like a solution (even thou I think I need to do something
SIMPLER)
but the namespace System.Reflection.Emit seems to be missing from the
compact framework

Any help will be highly appreciated (free coffee if you come to Milan
;) )

Ciao
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top