How can we unit test our C ++ COM code without registering a DLL?

We are trying to add unit testing to the deprecated C ++ COM application. We also need our assembly machines to be able to test unit tests so that each assembly does not introduce errors. However, we do not want compilers to be registered on prefabricated machines, so that one build machine can build several versions in parallel. We suggested that we can switch to using free registration with manifest files, but it’s very difficult for me to get this to work. Not on our code base, but only on a basic example provided by Microsoft.
I used this page http://msdn.microsoft.com/en-us/library/ms973913.aspx#rfacomwalk_topic8 and it just won't work, when I try to run with dll not registered to use manifest files, I get "Not registered class error "

The samples they provide work fine (using the C ++ com server and C ++ client), however, when I rebuild them, they do not work.

We use Visual Studio 2013, and therefore it seems to me that there have been significant changes in the way free registration works, which makes this tutorial incompatible with the new compiler.

Can someone tell me resources to use free registration with the latest version of visual studio? To complicate matters even further in our own application, when I get there, we use VS 2013, but we aim at the 2010 compiler, I hope this does not matter much.

Also, if there is a better way to run C ++ unit tests for lumpy components without registration than manifest files, I would also like to hear about that.

Thank you for your help.

+6
source share
2 answers

It is probably too late for the OP, but for someone else who comes across this issue, there is Samuel Jack's article about it here ... that may or may not help future readers ...

See http://blog.functionalfun.net/2012/09/a-quick-guide-to-registration-free-com.html

+2
source

You can implement your own version of CoCreateInstance, which uses an optional DLL path parameter. The code will be something like this (error handling and other information omitted for brevity):

HRESULT CoCreateInstanceForTest(dllPath, rclsid, riid, ppv) { HINSTANCE hinst = LoadLibrary(dllPath); // TODO: Maybe it is already loaded dllGetClassObject = GetProcAddress(hinst, "DllGetClassObject"); return dllGetClassObject(rclsid, riid, ppv); } 

In addition to error handling, you also need to track loaded DLLs. Use a list or array in which each element has a tuple to track this. At some point, you may need to unload all or some of them.

Of course, I assume that these are inproc COM servers.

+1
source

Source: https://habr.com/ru/post/971232/


All Articles