Good day.
Environment: Visual Studio 2008. Language: C++
(This is evolving into a two part question, I hope that's permitted...)
I have an ATL Project that I am working to replace an existing tool developed in an older version (VC++6, I believe, although nobody seems terribly sure).
I have created the ATL service (IScribe) using the wizard and have connected to it via a console application and have been moving to a Windows Form client in order to allow me to extend the testing environment (and as a proof of concept on a future potential use for the service).
I have added to the form the :
IIScribeServer* ISS;
and in the Form1_Load, I have the code:
BSTR message = NULL;
HRESULT hr;
hr = CoInitialize(0);
if(SUCCEEDED(hr))
{ hr = CoCreateInstance(
CLSID_IScribeServer,
NULL,
CLSCTX_INPROC_SERVER,
IID_IIScribeServer,
(void**) &ISS);
if(SUCCEEDED(hr))
{
long f5 = 5;
long f11 = 11;
hr = ISS-> GetCaption(&f5, &f11 , &message);
this->Text = gcnew System::String(message);
message = NULL;
}
}
Question 1:
If I declare the IIScribeServer within the Form1_Load event, it works fine.
If I declare it at the Form level, as in this code, I receive "error C2440: 'type cast' cannot convert from 'cli::interior_ptr<type> to 'void**'".
What would I be missing here to allow the conversion?
As a workaround: I added an intermediary call to allow the creation
BSTR message = NULL;
IIScribeServer *ISSb;
HRESULT hr;
and
if(SUCCEEDED(hr))
{ hr = CoCreateInstance(
CLSID_IScribeServer,
NULL,
CLSCTX_INPROC_SERVER,
IID_IIScribeServer,
(void**) &ISSb);
if(SUCCEEDED(hr))
{
ISX = ISXb;
ISXb = NULL;
And all works as I expect.
In a button click on the form, I do make a call to
HRESULT hr;
LONG puHi, puLo;
puHi = Convert::ToInt32(this->textBoxHighPart->Text);
puLo = Convert::ToInt32(this->textBoxLowPart->Text);
hr = ISS ->GetTimeStamp(&puHi, &puLo);
this->textBoxHighPart->Text = Convert::ToString((__int32)puHi);
this->textBoxLowPart->Text = Convert::ToString((__int32)puLo);
The
CoUninitialize()
is on the form close.
Which sends the values of the text box and performs minor math (add one, sub other) on them and replaces the text box. Nothing big.
This works fine and compiles in debug... but not in Release.
Question 2: Guh? I'm not sure where to start, but it doesn't build in Release.
(Q2 is SOLVED...
added a
#pragma comment ( lib, "ole32.lib" ) //to link the ole32 library
at the top and that took care of it.
)
From the Output window:
1>------ Build started: Project: InfWindow, Configuration: Release Win32 ------
1>Linking...
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall CoInitialize(void *)" (?CoInitialize@@$$J14YGJPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" void __stdcall CoUninitialize(void)" (?CoUninitialize@@$$J10YGXXZ)
1>C:\dev\Visual Studio 2008\Projects\IScribe\Release\InfWindow.exe : fatal error LNK1120: 3 unresolved externals
(these errors occur whether the IScribeServer * ISS; is at Form level or Form1_Load level)
Had to rename the objects to IScribeServer etc... in order to not flip some wigs here, apologies if transposition errors in teh above code in making those swap outs.