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.
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
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.
can get the code to compile only if I comment out my coclass andFrom a managed DLL app, after adding additional lib files for link, I
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