Click to See Complete Forum and Search --> : Loading Library and Threads


Fandu_Nagesh
April 9th, 2003, 07:39 AM
Dear Gurus
How to use CreateRemoteThread() in C# ?.. and

I want to load the C# Library with the help of LoadLibrary in VC++...Can we do like this ?. If yes then how to call a static function from that DLL..
Please help me....
Regards
Rajesh
:(

MartinL
April 10th, 2003, 04:18 AM
1.) CraeteRemoteThread is a Win32 stuff. As far as I know, you cant call CreateRemoteThread to the .NET application. You can import CreateRemoteThread to your .NET application and call it to the unmanaged application. I don't know what is the reason you need to create thread in other process, however you can't insert there managed code... :)

2.) You cannot load .net library using LoadLibrary from the unmanaged code. However, you can wrapp .net library using COM stuff and call CoCreateInstance on the classes in .net library. Also, there is possibility to mix call managed code from unmanaged C++ application if both codes are compiled in one project.

Martin

pareshgh
April 10th, 2003, 12:49 PM
Nagesh,

look this article , and as Martin suggested you could make a C++ dll and wrap it around.

CreateRemote (http://www.codeproject.com/system/hooksys.asp)


-Paresh

Fandu_Nagesh
April 11th, 2003, 07:33 AM
Dear Martin/Paresh
Thanx for repling my post....well Gurus...I think hooking for 3rd party application is not at all possible from the C# (I feel :) ). Even using WIn APIs from C#. It creats a lot problem.Self hooking is possible........ :)


1. C# made COM Dll loading is been doen as u said. Its working fine. Thnax for it.

2. Hooking issue is still open.... I got success in doing remote threading using VC++. So I played one trick. Hope so it will work. I kept all hooking related functions in VC++ and then I loaded that DLL in C#. and tring to achive the effect....Not yet successed....all idea and suggetions are invited for this method.....
If anyone of u konw the better way, Plz let me know....
ohhh....Martin asked me why u doing this....Basically my product whts is like that... He wanna capture the messages of 3rd party application...........
anyway....thanx for reply.....
Please let me know....or any sample if u come accross...
Reagrds
Nagesh

MartinL
April 13th, 2003, 12:43 PM
Hm...

I suppose, you are using CreateRemoteThread to achieve loading some dll in another process. Then you install WM_GETMESSAGE hook in the space of the other process. Am I right?

You want to call the hooking stuff from your C# code. So you created C++ dll that does it and loaded it into the C# app...

At the first. If you are trying to hook into the .NET application it might not work (I am not sure, but I believe that it is not possible by using CreateRemoteThread).

If you are trying to hook into the "normal" win32 application, it should work.

In this case, try your dll from C++ code.
-If the dll is not working also in C++ code, the problem is in your dll.

-If it works, then problem is in process that loads the dll. It is .NET application and this "deep win32 stuff" can work in different way.

In this case, I recommed you to write COM object to wrapp all these features and use it as surrogate com or make it out-of-process in other way (you can use .exe file or windows service). That solution divide your application into two processes. The first one, .NET based process, will just keep all stuff you have written in C#. The second one, win32 process, encapsulates hooking stuff and it is independent of the .NET application. Then it should work...

However, I am just guessing.. :D:D:D

martin