Header differerences between console app and DLL app with #import

D

dennishijk

I'm having trouble porting simple MS sample COM code from a console app
to the actual DLL app for my application. The code is pasted in from a
MS sample which was a console app.

The code compiles and executes as desired from a console app.
From a managed DLL app, after adding additional lib files for link, I
can get the code to compile only if I comment out my coclass and
interface definition from the type library.



Code below:

#include "stdafx.h"
#include <iostream>
#include "atlbase.h"
#import "..\Simulator\_Simulator.tlb" no_namespace
using namespace std;
struct OleCom {
OleCom() { CoInitialize(NULL);}
~OleCom() { CoUninitialize(); }
}olecom;
int _tmain(int argc, _TCHAR* argv[])
{
OleCom olecom;
CComPtr<IUnknown> spUnknown;
spUnknown.CoCreateInstance(__uuidof(CCQASimulator));
CComPtr<ICQASimulator> pI;
spUnknown.QueryInterface(&pI);
short res = 0;
CComBSTR devicefile("c:\\WUtemp\\abc.txt");
CComBSTR logfile ("def");
pI->SimulateDeviceToPC(devicefile.m_str,logfile.m_str);
CUSTOM_DATE date;
date.day = 02;
date.month = 8;
date.year = 1946;
cout << "Day " << date.day << " Month " << date.month << " Year " <<
date.year << endl;
pI->SetDate(&date);
date.year += 2;
pI->SetDate(&date);
CUSTOM_DATE* pDate = NULL;
pDate = pI->GetDate();
date.day = pDate->day;
date.month = pDate->month;
date.year = pDate->year;
cout << "Day " << date.day << " Month " << date.month << " Year " <<
date.year << endl;
::CoTaskMemFree(pDate);
pI->Simulate(STOne);
cout << res << endl;
return 0;
}

Dennis
 
D

dennishijk

I answered my own question,

Those pesky precompiled headers had to be turned off for the files with
native calls in the code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top