So I took a look at the article
Calling Managed .NET C# COM Objects from Unmanaged C++ Code[
] and was able to create my form and call it without issue. Now I would like to call the form multiple times allowing user to provide input each time. C or C++ it doesn't really matter and a mix of it is fine for my solution.
Is there something I'm missing? Shouldn't I be able to simply place the line below into a for loop?:
pDotNetCOMPtr->ShowCOMDialog ();
The form never appears after the first iteration. It's possible I'm misunderstanding the order of things, but I don't feel I should have to call CoInitialize or CreateInstance() again. Below is the simple code sample I'm using.
int _tmain(int argc, _TCHAR* argv[])
{
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
int theResult = -1;
long result = 0;
COMTesting::IProgramPtr pDotNetCOMPtr;
HRESULT hRes = pDotNetCOMPtr.CreateInstance(COMTesting::CLSID_Program);
for(int i = 0; i < 4;i++)
{
if (hRes == S_OK)
{
BSTR MyBstr = SysAllocString(L"Proof I can Pass a String!");
BSTR myReturnStr;
result = pDotNetCOMPtr->LaunchDialog(MyBstr, &myReturnStr);
printf("The Result was %i\r\n", result);
char *p = _com_util::ConvertBSTRToString(myReturnStr);
printf(p);
printf("\r\n");
printf("Press Any Key to Continue\r\n");
getchar();
delete [] p;
}
}
CoUninitialize ();
}
return 0;
}
Thank you so much for anyone that could provide assistance, or point me in the right direction if I'm misunderstanding how the COM calls are working.
EDIT: I realize that the return of my COM call actually results in a HRESULT. If this helps at all the first time it returns S_OK. Further iterations return what appear to be uninitialized values such as -2146233079