Solved

How to transalate this eVb code to evc code

Posted on 2004-08-05
29
1,649 Views
Last Modified: 2013-12-27
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?
0
Comment
Question by:weicheun
  • 16
  • 13
29 Comments
 

Author Comment

by:weicheun
ID: 11732782
Msync is to sync with oracle lite
0
 
LVL 23

Expert Comment

by:chensu
ID: 11737874
You are using COM objects. In C++, you will need to call CoCreateInstance().
0
 

Author Comment

by:weicheun
ID: 11779968
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
 
LVL 23

Expert Comment

by:chensu
ID: 11780729
As I already told you, you need to create the COM object and call the methods on its interface.
0
 

Author Comment

by:weicheun
ID: 11781091
can u show me how to write the code?
0
 
LVL 23

Expert Comment

by:chensu
ID: 11786234
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
 

Author Comment

by:weicheun
ID: 11791424
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
 
LVL 23

Expert Comment

by:chensu
ID: 11794760
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
 

Author Comment

by:weicheun
ID: 11808651
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
 
LVL 23

Expert Comment

by:chensu
ID: 11813628
CLSID c1;
IID i1;

::CLSIDFromString(L"8718BC04-A658-11D5-A2C6-00C04F81C073", &c1);
::CLSIDFromString(L"8718BC03-A658-11D5-A2C6-00C04F81C073", &i1);
0
 

Author Comment

by:weicheun
ID: 11818783
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
 
LVL 23

Expert Comment

by:chensu
ID: 11822736
Change

ISync : IDispatch* pInterface = NULL;

to

ISync *pInterface = NULL;

Or you need to call QueryInterface() on the pInterface to obtain ISync.
0
 

Author Comment

by:weicheun
ID: 11828936
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
 
LVL 23

Expert Comment

by:chensu
ID: 11835541
You need to query the ISync interface since doSync() is a member of ISync. Change IUnknown to ISync.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:weicheun
ID: 11853679
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
 
LVL 23

Expert Comment

by:chensu
ID: 11856589
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
 

Author Comment

by:weicheun
ID: 11858705
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
 
LVL 23

Expert Comment

by:chensu
ID: 11859990
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
 

Author Comment

by:weicheun
ID: 11868874
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
 

Author Comment

by:weicheun
ID: 11869713
Should I put "0x00000002" instead of 2 in first parameter or it makes no different?
0
 
LVL 23

Expert Comment

by:chensu
ID: 11873568
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
 

Author Comment

by:weicheun
ID: 11879687
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
 

Author Comment

by:weicheun
ID: 11879783
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
 
LVL 23

Expert Comment

by:chensu
ID: 11883851
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
 

Author Comment

by:weicheun
ID: 11893288
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
 
LVL 23

Expert Comment

by:chensu
ID: 11895083
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
 

Author Comment

by:weicheun
ID: 11901111
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
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 11904970
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
 

Author Comment

by:weicheun
ID: 11911063
thanks, u are a great help. :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

With Windows Embedded Handheld, called Windows Mobile, Microsoft re-designed the user interface. The Start Icon moved down to the bottom, inside the menu bar area.   If you need to hide the Start Icon and/or the SIP (soft input panel, softwar…
Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now