472,956 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,956 software developers and data experts.

Dynamicaly load and call a function in Win32 dll

Is it possible to dynamicaly to local and call a function in Win32 dll(not a
..net assembly dll) in C# at run time, for example, a C# program popup a
dialogbox to let use input which Win32 dll to be loaded, which function to
be called, and what are the parameters to call the function.
Thank you very much!
Jul 21 '05 #1
4 2810
Use reflection namespace for defining class and methods using data from your
dialog, compile it, load assembly and call.

HTH
Alex

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Is it possible to dynamicaly to local and call a function in Win32 dll(not a .net assembly dll) in C# at run time, for example, a C# program popup a
dialogbox to let use input which Win32 dll to be loaded, which function to
be called, and what are the parameters to call the function.
Thank you very much!

Jul 21 '05 #2
Alex,

Can you show me some sample code?
Thank you very much!

ZhangZQ
"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
Use reflection namespace for defining class and methods using data from your dialog, compile it, load assembly and call.

HTH
Alex

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Is it possible to dynamicaly to local and call a function in Win32 dll(not
a
.net assembly dll) in C# at run time, for example, a C# program popup a
dialogbox to let use input which Win32 dll to be loaded, which function

to be called, and what are the parameters to call the function.
Thank you very much!


Jul 21 '05 #3
> Is it possible to dynamicaly to local and call a function in Win32 dll(not
a
.net assembly dll) in C# at run time, for example, a C# program popup a
dialogbox to let use input which Win32 dll to be loaded, which function to
be called, and what are the parameters to call the function.


a partial solution is to write another Win32 dll that has fixed interface
and can dynamically load and call a function from Win32 library given by
name.

Regards,
Wiktor
Jul 21 '05 #4
You can start from
http://msdn.microsoft.com/library/de...dedomgraph.asp.

It's dynamic compilation topic. If you don't like this way, you can create
source code in any other suitable for you way - as file - and use csc.exe or
vbc.exe to make dll or exe, which will expose Win32 call to .net.

For every Win32 function you want to call in such way you need to know all
the details for DllImport attribute. In simple cases it is just what is the
type of returned result and what are the types of parameters to pass.

E.g. standard wrapper for SetWindowText might look like:

class Win32Wrapper {
public Win32Wrapper() {
[DllImport("User32")]
internal static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
...
public int Execute(IntPtr hWnd, int nCmdShow) {
return ShowWindow(hWnd,nCmdShow);
}
}
}

After you compile this, you can use Reflection to load resulting dll,
instantiate Win32Wrapper and call Execute with your parameters.

The rest is up to you. Which functions you want to define, which calls etc.

You can use similar approach when wrapper assembly is created in C++ 5 or 6,
or even VB6. Older style assemblies will require additional step - check
type library importer - tlbimp.exe. There is description what to do if you
want to change MSIL in assembly even, e.g.
http://msdn.microsoft.com/msdnmag/is...tprofilingapi/ - if you
really want to make this toy 100% dynamic and know how to modify IL.

Anyway, I think you should do your homework first. Copy/paste approach here
won't work really. For example, in this sample - how you plan to ask user to
specify hWnd parameter? Did you think about it already?

HTH
Alex

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:ux**************@TK2MSFTNGP09.phx.gbl...
Alex,

Can you show me some sample code?
Thank you very much!

ZhangZQ
"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
Use reflection namespace for defining class and methods using data from your
dialog, compile it, load assembly and call.

HTH
Alex

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Is it possible to dynamicaly to local and call a function in Win32 dll(not
a
.net assembly dll) in C# at run time, for example, a C# program popup a dialogbox to let use input which Win32 dll to be loaded, which

function to be called, and what are the parameters to call the function.
Thank you very much!



Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jmdeschamps | last post by:
Hello Having cx_Oracle (an Oracle database connector for Python) used it here where I teach for the last couple of years, and finding it so easy to use (and install) I was taken aback when I got...
4
by: ZhangZQ | last post by:
Is it possible to dynamicaly to local and call a function in Win32 dll(not a ..net assembly dll) in C# at run time, for example, a C# program popup a dialogbox to let use input which Win32 dll to...
3
by: lallous | last post by:
Hello I'm new to C# and wonder if it is possible, as it is possible in C++, to dynamically load a DLL and use it in C#. The dll is written in C++ (unmanaged) and has the following export: ...
3
by: Daniel | last post by:
How do i dynamicaly load and unload a C# dll at runtime
1
by: Andrew Moore | last post by:
Hello, I have a Managed C++ dll to contain an AVI Capture tool. This dll contains a __gc class to interface with a C# application, and a __nogc class to contain calls to the Win32 API and VFW...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
1
by: Mythran | last post by:
I am attempting to read all of the resources from a Win32 executable, and load each of them to display them on a screen. So, please help figure out why I can't seem to get it right :) First...
5
by: Paul Cheetham | last post by:
Hi, I have some custom colour cursors which I have added to my c# project, and set them to be compiled as "Embedded Resource" It seems impossible to load a colour cursor using the standard...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.