Passing Object Pointers In COM
-
HELP ! I am VERY new to COM (3 days experience) and I want to do something which may sound a bit odd. I wish to take a pointer to a C++ object from one application and pass it via COM to another C++ application. The only stuff I have found on doing this involves serializing the objet to a CMemFile and passing it as a string. The Object I wish to pass is a container and I do not wish to make everything it holds serializable, problem. If anybody can help me it would be nice. Thanks
On the other hand it would be better to create a COM wraper for the object that you are passing. And than just pass the interface pointer.
-
You can try to get pointer to your object and then pass it to your COM object as LONG. That way your COM object will know the memory location of the object you are passing. Peter
I have tried passing the pointer to the object as long. When I do this it does not appear (when debugging the COM)to have the same value it had in the app which created it. Also I could not get the long value back into the second app, it had a different value. Puzzled !
-
On the other hand it would be better to create a COM wraper for the object that you are passing. And than just pass the interface pointer.
How do I create a COM wrapper ? Remember I am very new to COM.
-
HELP ! I am VERY new to COM (3 days experience) and I want to do something which may sound a bit odd. I wish to take a pointer to a C++ object from one application and pass it via COM to another C++ application. The only stuff I have found on doing this involves serializing the objet to a CMemFile and passing it as a string. The Object I wish to pass is a container and I do not wish to make everything it holds serializable, problem. If anybody can help me it would be nice. Thanks
>I wish to take a pointer to a C++ object from one application and pass it via COM to another C++ application. You cannot do this, COM or no COM. Each Win32 app has its own isolated memory space. A pointer in app A has no meaning if you pass it to app B. You'll need to use IPC (inter-process communication) techniques to pass data between apps. There are articles here at CP on doing this - give them a read. (You are sort-of on the right track with CMemFile, but CMemFile is not a memory-mapped file, which is the IPC mechanism you're thinking of.)
-
I have tried passing the pointer to the object as long. When I do this it does not appear (when debugging the COM)to have the same value it had in the app which created it. Also I could not get the long value back into the second app, it had a different value. Puzzled !
If your com is an exe the passing a pointer as long will not work since the com is in a diferent process and therefore the address in the long is not valid. Passing pointers as long will work only if your COM is a dll. (Don't forget to cast the pointer in both sides back to the structure it points to, before using it).
-
HELP ! I am VERY new to COM (3 days experience) and I want to do something which may sound a bit odd. I wish to take a pointer to a C++ object from one application and pass it via COM to another C++ application. The only stuff I have found on doing this involves serializing the objet to a CMemFile and passing it as a string. The Object I wish to pass is a container and I do not wish to make everything it holds serializable, problem. If anybody can help me it would be nice. Thanks
What exactly are you trying to do? What does this C++ do that separate applications need access to it? You might want to put the C++ object in a separate COM object and have it shared between processes.
-
What exactly are you trying to do? What does this C++ do that separate applications need access to it? You might want to put the C++ object in a separate COM object and have it shared between processes.
I am using one app to do an external equipment search (this takes a while) and store the objects it created (one per equipment present) in a COM server. I want many other applications on the same machine to be able to query the COM server to get pointers to the objects. So Equipment search app -> COM server COM Server -> Testing App 1 COM Server -> Testing App 2 etc I do not want to have to go through all my equipment classes and make them serializable. Thanks :confused: :confused:
-
I am using one app to do an external equipment search (this takes a while) and store the objects it created (one per equipment present) in a COM server. I want many other applications on the same machine to be able to query the COM server to get pointers to the objects. So Equipment search app -> COM server COM Server -> Testing App 1 COM Server -> Testing App 2 etc I do not want to have to go through all my equipment classes and make them serializable. Thanks :confused: :confused:
Then I would wrap your C++ class in a COM object. You can pass an interface pointer from your server to the clients so they may access the C++/COM object.
-
I am using one app to do an external equipment search (this takes a while) and store the objects it created (one per equipment present) in a COM server. I want many other applications on the same machine to be able to query the COM server to get pointers to the objects. So Equipment search app -> COM server COM Server -> Testing App 1 COM Server -> Testing App 2 etc I do not want to have to go through all my equipment classes and make them serializable. Thanks :confused: :confused:
Then I would wrap your C++ class in a COM object. You can pass an interface pointer from your server to the clients so they may access the C++/COM object.
-
Then I would wrap your C++ class in a COM object. You can pass an interface pointer from your server to the clients so they may access the C++/COM object.
Which class, the container or each of the equipment classes (many different types) ?