Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » OLE Automation (Request more help with OLE Automation)
Re: OLE Automation [message #51300 is a reply to message #51294] Mon, 04 March 2019 10:35 Go to previous messageGo to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello Pradip,

Response 1 :
Error : E:\UPP_Projects\Testing\main.cpp (33): error C2065: 'CP_ACP': undeclared identifier
E:\UPP_Projects\Testing\main.cpp (33): error C3861: 'WideCharToMultiByte': identifier not found

Maybe you need one of this both header : #include <windows.h> #include <ole2.h>

Response 2 :
Using CLSIDFromProgID is Ok. I forgot to speak about it in my first post.

Response 3 :
If you need to catch an STAAD Instance instead of create one you can use GetActiveObject
But you will MAYBE need to cast your IUnknown** to something like an IID_IDispatch
using QueryInterface function of IUnknown.

Here is one example :

CLSID clsApp;
VARIANT App = {0};
IUnknown* punk;
HRESULT hr = CLSIDFromProgID(appName, &clsApp); 
if(!FAILED(hr)){
	HRESULT hr2 =GetActiveObject( clsApp, NULL, &punk );
	if (!FAILED(hr2)) {
	      hr2=punk->QueryInterface(IID_IDispatch, (void **)&App.pdispVal);
         }
}

After this code my IUnknown representing the application we catched (here is STAAD) will be 'cast' into a VARIANT using QueryInterface.
But be carefull not every OLE Object need to be cast to VARIANT, it depend on the application which you want to interact.

Response 4 :
Indeed, it's a bit more complicated to read String from VARIANT. First, you must know String is stored into yourVariant.bstrVal
but this one is a not a char* or std/Upp string type. This one is a BSTR (it's the same thing as a wchar*). so here is a function to cast it into Upp::String :
//conversion BSTR to CHAR
//Don't forget #include <stdio.h>
Upp::String BSTRtoString (BSTR bstr)
{
    std::wstring ws(bstr);
    std::string str(ws.begin(), ws.end());
    return Upp::String(str);
}

and here is how to use it :
Upp::String valueOfVariant =  BSTRtoString(myVariant.bstrVal);		


"And how about using properties which perhaps return arrays of int or double (the getbeamlength in fact returns an array of double)." To this one I have no idea... it never happen to me.
but here seems to be a good exemple of how to do it : https://www.codeguru.com/cpp/cpp/cpp_mfc/arrays/article.php/ c767/Functions-for-Setting-and-Retrieving-Values-from-Varian t-Safe-Arrays.htm


Hope it helped you.

have a good day.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: U++ with Visual Studio 2017?
Next Topic: [solved] Is it an encoding problem ?
Goto Forum:
  


Current Time: Sun Apr 28 23:00:33 CEST 2024

Total time taken to generate the page: 0.04988 seconds