1
votes

I've written a com dll using VS2012. I got 2 projects - my DLL project and a PS Project. PS has 3 classes: myproj_i.h myProj_i.c myProj_p.c

now I want to call the dll from another MFC project:

hr = CoCreateInstance( CLSID_MYTASK, NULL, CLSCTX_INPROC_SERVER, IID_IMYTASK, (void**) &pMYTASK );

I have included the myproj_i.h file - so I get all the symbols recognised, yet I can't link them, as I'm missing the _i.c file.

If I add them to the project I get planty of PCH errors.

How should I Link my MFC project and call the DLL ?

I have also tried to use #import of the dll but then I get missing TLH error, and I haven't found that file in the DLL project.

Including the myProjPS.lib did not solve it either...

1
PS project is needed for specific marshaling scenarios, chances are high you don't need it at all. If you do, perhaps it's worth better explaining the ultimate goal. The easiest inclusion is using #import, have a look there - code snippet.Roman R.
I've tried to import but I get an error look for a .tlh file which I don't have...I probably don't need it, it was there so I used it. I pass strings and long between the mfc and the atl dll, that's all.Dani

1 Answers

1
votes

MIDL-generated .c files do not use precompiled headers. If you link them into your program (I usually make static libs of them, but that's a different method), you need to turn OFF precompiled headers for those specific .c files.

  • Right-click the myProj_i.c file in the soluton explorer and bring up its properties.
  • Select All Platforms/All configurations in the top two drop lists.
  • Expand the C++ Settings in the left tree.
  • Select Precompiled Headers in the left tree
  • Switch them OFF for that file.

That should allow it to compile and link successfully.