473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 2835
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.