Click here to Skip to main content
15,907,183 members
Home / Discussions / COM
   

COM

 
GeneralRe: LPSTR and LPBYTE passing to a dll Pin
JonEngle6-Dec-05 10:27
JonEngle6-Dec-05 10:27 
QuestionDLLHost.exe Terminates on Windows Server 2003 Pin
Gupta Suraj5-Dec-05 19:15
Gupta Suraj5-Dec-05 19:15 
QuestionHow "DCOM server process launcher" works? Pin
Chintoo7235-Dec-05 17:30
Chintoo7235-Dec-05 17:30 
AnswerRe: How "DCOM server process launcher" works? Pin
Chintoo7235-Dec-05 17:44
Chintoo7235-Dec-05 17:44 
QuestionOut-of-process COM in C# Pin
london_ste2-Dec-05 4:57
london_ste2-Dec-05 4:57 
AnswerRe: Out-of-process COM in C# Pin
Lim Bio Liong5-Dec-05 13:13
Lim Bio Liong5-Dec-05 13:13 
GeneralRe: Out-of-process COM in C# Pin
london_ste8-Dec-05 6:17
london_ste8-Dec-05 6:17 
GeneralRe: Out-of-process COM in C# Pin
Lim Bio Liong8-Dec-05 16:03
Lim Bio Liong8-Dec-05 16:03 
Hello london_ste,

>> Or do you mean the DLL can instantiate and call directly into the exe which will be runnig outof-process ad somehow hold onto the reference to itso we can call more methods on the external exe?

Yes, this is what I mean. This DLL is what I refer to as the "Factory" DLL. It is also a .NET Assembly (a class library). Hence we will be working with at least 2 .NET Assemblies : the "factory" assembly and the .NET Exe Assembly which supplies the class that we want to expose to an unmanaged client.

This is how it works : an unmanaged client first talks to the "factory" assembly DLL through COM interface methods that are wrapped in a COM-Callable Wrapper. Let's call this interface the "factory" interface. Internally, the "factory" interface method performs the actual instantiation of the .NET class from the .NET Exe.

An example of such a "factory" method is :

public object CreateInstance_ByActivation(string strAssemblyName, string strTypeName);

The "factory" interface method can do the instantiation via Activation/Reflection or Remoting. After instantiating the .NET class instance (in the .NET Exe), the "factory" interface method delivers the .NET object directly to the unmanaged client by its return value (of type "object", which is translated into an "out" VARIANT parameter by COM interop).

An unmanaged client (written in C++, say) can call this method as follows :

VARIANT varRet;
...
...
...
IFactory -> CreateInstance_ByActivation
(
bstrAssemblyName,
bstrTypeName,
&varRet
);

The .NET object (housed in the .NET Exe Assembly) will be returned via the VARIANT "varRet". "varRet" will contain either an IUnknown pointer or an IDispatch pointer depending on how the class in the .NET Exe is attributed. You would retrieve the interface pointer by using the usual variant macros and functions, e.g. :

if ((V_VT(&varRet) != VT_EMPTY) && (V_UNKNOWN(&varRet) != NULL))
{
*ppTargetObjectUnknown = V_UNKNOWN(&varRet);

(*ppTargetObjectUnknown) -> AddRef();
}

Note that after the .NET Exe Class object has been delivered to the client this way, the "factory" is no longer needed. The client interacts with the object directly. This can be in the form of IDispatch::Invoke() or, if the client has the interface signature of the object, in the form of direct interface method calls (but QueryInterface() must be called on the returned IUnknown pointer first).

With several more developers recently asking for essentially the same information, I think I may want to write my article on this as soon as possible.

Concerning Remoting, there are many good introductory articles in CodeProject. I do recommend one written by me last year :

Simple but potentially useful example of .NET Remoting
http://www.codeproject.com/csharp/ProcessActivator.asp[^]

and

A Simple But Useful Example of .NET Remoting Part 2
http://www.codeproject.com/csharp/ProcessActivator2.asp[^]

Contact me again if you need further clarification.

Best Regards,
Bio.




-- modified at 4:13 Friday 9th December, 2005
Questionwhy to put extern C before const IID? Pin
Lane Yu1-Dec-05 23:32
Lane Yu1-Dec-05 23:32 
AnswerRe: why to put extern C before const IID? Pin
Marco M.6-Dec-05 8:33
Marco M.6-Dec-05 8:33 
Questionis it possible to Call web-service from COM component? Pin
Amol Ravatale29-Nov-05 18:34
Amol Ravatale29-Nov-05 18:34 
AnswerRe: is it possible to Call web-service from COM component? Pin
Lim Bio Liong29-Nov-05 19:06
Lim Bio Liong29-Nov-05 19:06 
GeneralServiced Component, Excel and OleDbConnection.Open Pin
Turtle Hand28-Nov-05 9:45
Turtle Hand28-Nov-05 9:45 
GeneralRe: Serviced Component, Excel and OleDbConnection.Open Pin
Turtle Hand1-Dec-05 4:14
Turtle Hand1-Dec-05 4:14 
QuestionEvent sink in MFC-program - Thread problem? Pin
-Tom-26-Nov-05 4:25
-Tom-26-Nov-05 4:25 
AnswerRe: Event sink in MFC-program - Thread problem? Pin
Roger Stoltz5-Dec-05 5:27
Roger Stoltz5-Dec-05 5:27 
QuestionPorting Win32/COM to Linux Pin
Jnewg526-Nov-05 1:24
Jnewg526-Nov-05 1:24 
AnswerRe: Porting Win32/COM to Linux Pin
Jörgen Sigvardsson26-Nov-05 12:55
Jörgen Sigvardsson26-Nov-05 12:55 
QuestionGetUIObjectOf for objects on different drives Pin
yarp25-Nov-05 2:35
yarp25-Nov-05 2:35 
QuestionWord automation problem with C++ Pin
panzerdivisionmarkus24-Nov-05 1:47
panzerdivisionmarkus24-Nov-05 1:47 
AnswerRe: Word automation problem with C++ Pin
JonEngle6-Dec-05 18:55
JonEngle6-Dec-05 18:55 
QuestionHow to pass a object of a .NET user defined type to a COM in VC++? Pin
Diana Fernandez23-Nov-05 18:09
Diana Fernandez23-Nov-05 18:09 
AnswerRe: How to pass a object of a .NET user defined type to a COM in VC++? Pin
Gizzo24-Nov-05 6:11
Gizzo24-Nov-05 6:11 
GeneralRe: How to pass a object of a .NET user defined type to a COM in VC++? Pin
Diana Fernandez24-Nov-05 20:11
Diana Fernandez24-Nov-05 20:11 
GeneralRe: How to pass a object of a .NET user defined type to a COM in VC++? Pin
Gizzo24-Nov-05 21:25
Gizzo24-Nov-05 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.