How to transalate this eVb code to evc code

I am trying to translate the EVB code below to Embeded Visual C++:

Dim sync As MSync.sync
Set sync = CreateObject("MSync.Sync")

Dim oRAS As CEUTILSLibCtl.RASConnection
Set oRAS = CreateObject("CEUtils.RASConnection")

PDAConn = oRAS.Connection

msync is an exe file and ceutil is a dll file. How can i accomplish the same thing with evc++
 
how do i declare and use the dll in evc?
weicheunAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
You need to use DISPATCH_PROPERTYGET instead of DISPATCH_METHOD with no arguments. But the 6th parameter needs to be the address of a VARIANT to receive the result.
0
 
weicheunAuthor Commented:
Msync is to sync with oracle lite
0
 
chensuCommented:
You are using COM objects. In C++, you will need to call CoCreateInstance().
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
weicheunAuthor Commented:
My program will start a third party program(MSYNC). I want my program to press/execute the "SYNC" button in the program. How do I do that without instucting the mouse to move to the cordinate of sync button and click?

in Visual Basic its just MSYNC.sync but i can't figure out how to do it in C++
0
 
chensuCommented:
As I already told you, you need to create the COM object and call the methods on its interface.
0
 
weicheunAuthor Commented:
can u show me how to write the code?
0
 
chensuCommented:
There is nothing special. Just like any COM calls,

HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

IYourInterface *pInterface = NULL;

hr = ::CoCreateInstance(CLSID_YOURCLSID, NULL, CLSCTX_INPROC_SERVER, IID_YOURINTERFACE, (void **)&pInterface);

if (SUCCEEDED(hr))
{
    pInterface->TheMethod();

    pInterface->Release();
}

::CoUninitialize();
0
 
weicheunAuthor Commented:
what should i put into the fifth parameter?

I put {16F4A261-A648-11D5-A2C5-00C04F81C073} in the first parameter.

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: <could not determine filename>

[
  uuid(16F4A254-A648-11D5-A2C5-00C04F81C073),
  version(1.0),
  helpstring("mSync 1.0 Type Library")
]
library MSYNC
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    dispinterface _ISyncProgressListenerEvents;
    interface ISyncOption;
    interface ISync;
    interface ISyncProgressListener;

    [
      uuid(BD359C39-AE10-11D5-A2C7-00C04F81C073),
      helpstring("_ISyncProgressListenerEvents Interface")
    ]
    dispinterface _ISyncProgressListenerEvents {
        properties:
        methods:
            [id(0x00000001), helpstring("method progress")]
            HRESULT progress(
                            [in] int progressType,
                            int param1,
                            int param2);
    };

    [
      uuid(16F4A261-A648-11D5-A2C5-00C04F81C073),
      helpstring("SyncOption Class")
    ]
    coclass SyncOption {
        [default] interface ISyncOption;
    };

    [
      odl,
      uuid(16F4A260-A648-11D5-A2C5-00C04F81C073),
      helpstring("ISyncOption Interface"),
      dual,
      oleautomation
    ]
    interface ISyncOption : IDispatch {
        [id(0x00000001), helpstring("method load")]
        HRESULT load();
        [id(0x00000002), propget, helpstring("property username")]
        HRESULT username([out, retval] BSTR* pVal);
        [id(0x00000002), propput, helpstring("property username")]
        HRESULT username([in] BSTR pVal);
        [id(0x00000003), propget, helpstring("property password")]
        HRESULT password([out, retval] BSTR* pVal);
        [id(0x00000003), propput, helpstring("property password")]
        HRESULT password([in] BSTR pVal);
        [id(0x00000004), helpstring("method getBytes")]
        HRESULT getBytes([out] BSTR* bytes);
        [id(0x00000005), propget, helpstring("property transporType")]
        HRESULT transporType([out, retval] BSTR* pVal);
        [id(0x00000005), propput, helpstring("property transporType")]
        HRESULT transporType([in] BSTR pVal);
        [id(0x00000006), propget, helpstring("property transportParam")]
        HRESULT transportParam([out, retval] BSTR* pVal);
        [id(0x00000006), propput, helpstring("property transportParam")]
        HRESULT transportParam([in] BSTR pVal);
        [id(0x00000007), helpstring("method save")]
        HRESULT save();
    };

    [
      uuid(8718BC04-A658-11D5-A2C6-00C04F81C073),
      helpstring("Sync Class")
    ]
    coclass Sync {
        [default] interface ISync;
        [default, source] dispinterface _ISyncProgressListenerEvents;
    };

    [
      odl,
      uuid(8718BC03-A658-11D5-A2C6-00C04F81C073),
      helpstring("ISync Interface"),
      dual,
      oleautomation
    ]
    interface ISync : IDispatch {
        [id(0x00000002), helpstring("method doSync")]
        HRESULT doSync();
        [id(0x00000003), helpstring("method setOptionObject")]
        HRESULT setOptionObject([in] ISyncOption* pISyncOption);
        [id(0x00000004), propget, helpstring("property lastErrorCode")]
        HRESULT lastErrorCode([out, retval] long* pVal);
        [id(0x00000005), propget, helpstring("property lastErrorMessage")]
        HRESULT lastErrorMessage([out, retval] BSTR* pVal);
    };

    [
      uuid(BD359C38-AE10-11D5-A2C7-00C04F81C073),
      helpstring("SyncProgressListener Class")
    ]
    coclass SyncProgressListener {
        [default] interface ISyncProgressListener;
        [default, source] dispinterface _ISyncProgressListenerEvents;
    };

    [
      odl,
      uuid(BD359C37-AE10-11D5-A2C7-00C04F81C073),
      helpstring("ISyncProgressListener Interface"),
      dual,
      oleautomation
    ]
    interface ISyncProgressListener : IDispatch {
        [id(0x00000001), helpstring("method progress")]
        HRESULT progress(
                        [in] int progressType,
                        int param1,
                        int param2);
    };
};
0
 
chensuCommented:
Depending on which interface you need to use, the first parameter is the class ID and the fourth parameter is the interface ID. For example,

[
      uuid(8718BC04-A658-11D5-A2C6-00C04F81C073),
      helpstring("Sync Class")
    ]
    coclass Sync {
        [default] interface ISync;
        [default, source] dispinterface _ISyncProgressListenerEvents;
    };

    [
      odl,
      uuid(8718BC03-A658-11D5-A2C6-00C04F81C073),
      helpstring("ISync Interface"),
      dual,
      oleautomation
    ]

Above, the first uuid is the class ID and the second uuid is the interface ID.
0
 
weicheunAuthor Commented:
what's wrong with my code?
1)REFCLSID pclsid =NULL;
2)REFIID intcid =NULL ;
3)CLSIDFromString(TEXT("8718BC04-A658-11D5-A2C6-00C04F81C073"),pclsid ) ;
4)CLSIDFromString(TEXT("8718BC03-A658-11D5-A2C6-00C04F81C073"),intcid) ;
5)hr = ::CoCreateInstance(pclsid, NULL, CLSCTX_INPROC_SERVER, intcid, (void **)&pInterface);

error message:
1)'initializing' : cannot convert from 'const int' to 'const struct _GUID        
3)'CLSIDFromString' : cannot convert parameter 2 from 'const struct _GUID' to 'struct _GUID *'
5)'CoCreateInstance' : cannot convert parameter 4 from 'struct _GUID *' to 'const struct _GUID &'
       
       
0
 
chensuCommented:
CLSID c1;
IID i1;

::CLSIDFromString(L"8718BC04-A658-11D5-A2C6-00C04F81C073", &c1);
::CLSIDFromString(L"8718BC03-A658-11D5-A2C6-00C04F81C073", &i1);
0
 
weicheunAuthor Commented:
Thanks, now I got another problem?
I received this  error message:
 'doSync' : is not a member of 'IDispatch'

Here's my code:

#include <windows.h>
#include <Objbase.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
 HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
 CLSID c1;
 IID i1;
 ::CLSIDFromString(L"8718BC04-A658-11D5-A2C6-00C04F81C073", &c1);
 ::CLSIDFromString(L"8718BC03-A658-11D5-A2C6-00C04F81C073", &i1);
 ISync : IDispatch* pInterface = NULL;
 hr = ::CoCreateInstance(c1, NULL, CLSCTX_INPROC_SERVER, i1, (void **)&pInterface);
 pInterface-> doSync();
 pInterface->Release();
 ::CoUninitialize();

 return 0;
}
0
 
chensuCommented:
Change

ISync : IDispatch* pInterface = NULL;

to

ISync *pInterface = NULL;

Or you need to call QueryInterface() on the pInterface to obtain ISync.
0
 
weicheunAuthor Commented:
The first way doesn't help, just give me the same error message . I have tried to call QueryInterface() by adding the few line below and got the same error message. Note, I used the same "interface ID" for CoCreateInstance, is it correct?

IUnknown *punk = NULL;
 
hr = ::CoCreateInstance(c1, NULL, CLSCTX_INPROC_SERVER, i1, (void **)&pInterface);

pInterface->QueryInterface(i1, (void**)&punk);
punk-> doSync();

error message:
 "doSync' : is not a member of 'IUnknown'"  
0
 
chensuCommented:
You need to query the ISync interface since doSync() is a member of ISync. Change IUnknown to ISync.
0
 
weicheunAuthor Commented:
I used 8718BC03-A658-11D5-A2C6-00C04F81C073, which is the id for ISync interface I believe. When I change IUnknown to ISync, i received an error message which said ISync is not define.
0
 
chensuCommented:
Since you don't have a header file that has ISync defined, you will have to use IDispatch and call IDispatch::Invoke() on the methods you want to call. The dispid for doSync() is 2 according to the info you showed above.
0
 
weicheunAuthor Commented:
does Invoke() only enable one method at a time?
btw, how do i write the code to define ISync in header file?

-->me dumb java programmer :), C++ is kind of cryptic to me.
0
 
chensuCommented:
Invoke() will call one method at a time. In order to call another method, you need to call Invoke() again with the dispid.

Do you have the source code of the COM object (MSync.Sync)? The header file is generated when you compile the IDL file.
0
 
weicheunAuthor Commented:
hr = DISP_E_EXCEPTION when I do it this way:
-DISP_E_EXCEPTION The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.

DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
EXCEPINFO FAR *pExcepInfo;
IID i2;

hr=pInterface->Invoke(2,i2,NULL,DISPATCH_METHOD,&dispparamsNoArgs,NULL,pExcepInfo,NULL);

plus according to help file, second parameter is "Reserved for future use; set to IID_NULL"
but I received "error LNK2019: unresolved external symbol GUID_NULL referenced in function WinMain"
when I put IID_NULL in second parameter and build the application(no error if I compile only).
0
 
weicheunAuthor Commented:
Should I put "0x00000002" instead of 2 in first parameter or it makes no different?
0
 
chensuCommented:
hr=pInterface->Invoke(2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, NULL, NULL, NULL);

For IID_NULL, add uuid.lib to your linker options.
0
 
weicheunAuthor Commented:
I still get "DISP_E_EXCEPTION" when I invoke "doSync"

 "HRESULT lastErrorCode([out, retval] long* pVal);"
and how do I invoke method with 1 out parameter like "lastErrorCode"
I get "DISP_E_MEMBERNOTFOUND" when I did the same thing as invoking "doSync" ?
0
 
weicheunAuthor Commented:
Should I use this for "lastErrorCode"
DISPPARAMS dispparams;
dispparams.rgvarg[0].vt = VT_BYREF|VT_BSTR;
dispparams.rgvarg[0].pbstrVal = &xmlInput;
dispparams.rgdispidNamedArgs = NULL;
dispparams.cArgs = 1;
dispparams.cNamedArgs = 0;
0
 
chensuCommented:
Have you registered the COM DLL successfully on the CE device?

If you get DISP_E_EXCEPTION,

EXCEPINFO einfo;

hr=pInterface->Invoke(2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparamsNoArgs, NULL, &einfo, NULL);

then have a look at the einfo.
0
 
weicheunAuthor Commented:
I received "DoSync failed". My guess is, it's because I didn't have Oracle Lite on the desktop so it can't sync with it.  

Now I need to know what values I need to assign to DISPPARAMS for "HRESULT lastErrorCode([out, retval] long* pVal);"
to work.Is this ok:

DISPPARAMS dispparams;
dispparams.rgvarg[0].vt = VT_I4 | VT_BYREF ;      //  A reference to a 4-byte integer was passed
dispparams.rgdispidNamedArgs = NULL;
dispparams.cArgs = 1;
dispparams.cNamedArgs = 0;
0
 
chensuCommented:
It should be

long lVal = 0;

DISPPARAMS dispparams;
dispparams.rgvarg[0].vt = VT_I4 | VT_BYREF ;      //  A reference to a 4-byte integer was passed
dispparams.rgvarg[0].plVal = &lVal;
dispparams.rgdispidNamedArgs = NULL;
dispparams.cArgs = 1;
dispparams.cNamedArgs = 0;
0
 
weicheunAuthor Commented:
ops, actually I need to transalate a method equalvalent to "lastErrorMessage" not "lastErrorCode".
dispinterface ISync{
-[id(0x00000005), propget, helpstring("property lastErrorMessage")]
-BSTR lastErrorMessage();}

interface ISync : IDispatch {
-[id(0x00000005), propget, helpstring("property lastErrorMessage")]
-HRESULT lastErrorMessage([out, retval] BSTR* pVal);}

I try LastErroMessage with this code:
BSTR lVal;
DISPPARAMS dispparams;
dispparams.rgvarg[0].vt = VT_BYREF|VT_BSTR;
dispparams.rgvarg[0].pbstrVal = &lVal;
dispparams.rgdispidNamedArgs = NULL;
dispparams.cArgs = 1;
dispparams.cNamedArgs = 0;
pInterface->Invoke(5, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &parms, NULL, &pExcepInfo, NULL);

And I received this runtime error:
-Fatal Application Error
-Application test3.exe has performed an illegal operation and will be shut down.
-Exception: 0xc0000005


0
 
weicheunAuthor Commented:
thanks, u are a great help. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.