You can start from
http://msdn.microsoft.com/library/d...ourcecodecompilingprogramfromcodedomgraph.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/issues/03/09/netprofilingapi/ - 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