Home > Software engineering >  Call com plug-in, the console program crash, in normal use dialog program, why
Call com plug-in, the console program crash, in normal use dialog program, why

Time:09-25

A call to a same com plug-in, why create a win32 console exe program can not run, in MFC app. Exe program can run,

Intermediate code simply changed my foundation is weak, will only simple resources change, but now it is in urgent need of application,
The great spirit guide, please where is wrong, thank you

I need a console program here, dialog application is not suitable for my use environment,

Programming environment is Windows 7, 64, the simplest version of the vc6.0,

The two main difference is the console program code used CoCreateInstance, dialog box with the CreateDispatch
Is reference for other people's code, so, why there is something wrong with my console?



//win32 console exe
//to the original can run the project, just set up class wizard, add the DLL external references, engineering document automatically add the dm. CPP, dm. H two files,
//at the beginning of the main program there added the following three lines

H # include "Windows."
//call the desert component
#include
# include "dm. H"


Idmsoft * dm=NULL;
CoInitialize (NULL);

Clsids clsids;

Retrieves the hr=CLSIDFromProgID (OLESTR (" dm. Dmsoft "), & amp; Clsids);

IID IID_Idmsoft;
Hr=IIDFromString (OLESTR (" dm. Dmsoft "), & amp; IID_Idmsoft);

Hr=CoCreateInstance (clsids, NULL, CLSCTX_ALL, IID_Idmsoft, (LPVOID *) & amp; Dm);//doubt this function out of the question,

Dm - & gt; MoveTo (100100);
Sleep (10000);

CoUninitialize ();

-=-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//the new set up a dialog box procedure, MFC exe,
//in the same building class wizard, add the DLL external references, engineering document automatically add the dm. CPP, dm. H two files,
//Dlg. CPP add:
# include "dm. H"

//the ONOK response


Idmsoft Dm;//put this definition has been here won't have the problem of collapses,

Clsids clsids;
Retrieves the hr=CLSIDFromProgID (OLESTR (" dm. Dmsoft "), & amp; Clsids);
Dm. CreateDispatch (clsids);

Dm. MoveTo (100100);
Sleep (1000);
Dm. MoveTo (500100);
Sleep (1000);
Dm. MoveTo (500500);
Sleep (1000);

//this dialog normal reaction,


==============
//hr=CoCreateInstance (clsids, NULL, CLSCTX_ALL, IID_Idmsoft, (LPVOID *) & amp; Dm);//doubt this function out of the question,

//Dm. CreateDispatch (clsids);
The two main difference is the console program code used CoCreateInstance, dialog box with the CreateDispatch
Is reference for other people's code, so, why there is something wrong with my console?


CodePudding user response:

Master to help me solve methods, such as,

CodePudding user response:

Less people good ah, I also hope to solve?
The whole days, stare blankly is don't know what to do

CodePudding user response:


If I delete the following three lines
IID IID_Idmsoft;
Hr=IIDFromString (OLESTR (" dm. Dmsoft "), & amp; IID_Idmsoft);

Hr=CoCreateInstance (clsids, NULL, CLSCTX_ALL, IID_Idmsoft, (LPVOID *) & amp; Dm);//doubt this function out of the question,
And then use this line to replace
Hr=CoCreateInstance (clsids, NULL, CLSCTX_INPROC_SERVER, __uuidof (Idmsoft), (LPVOID *) & amp; Dm);
Compile time will come out this error message
The error C2787: 'Idmsoft: no GUID has had been associated with this obj

CodePudding user response:

Repetition you environment people are hard to give you, for 2020 years, using VC6 people sincerely, this is you at the first glance like a GUI or comctrl failed to initialize the appearance, but it's true it's hard to say, can only be clear, debugging

CodePudding user response:

Header file then posted up here, I see what is missing?

//Machine generated IDispatch wrapper class (es) created with ClassWizard
/////////////////////////////////////////////////////////////////////////////
//Idmsoft wrapper class

The class Idmsoft: public COleDispatchDriver
{
Public:
Idmsoft () {}//Calls COleDispatchDriver default constructor
Idmsoft (LPDISPATCH pDispatch) : COleDispatchDriver (pDispatch) {}
Idmsoft (const Idmsoft& DispatchSrc) : COleDispatchDriver (dispatchSrc) {}

//the Attributes
Public:

//Operations
Public:
Cstrings Ver ();
Long SetPath (LPCTSTR path);
Cstrings Ocr (long x1, long y1, long x2, long y2, LPCTSTR color, double sim);
Long FindStr searches (long x1, long y1, long x2, long y2, LPCTSTR STR, LPCTSTR color, double sim, the VARIANT * x, the VARIANT * y);
Long GetResultCount LPCTSTR (STR);
Long GetResultPos (LPCTSTR STR, long index, the VARIANT * x, the VARIANT * y);
Long StrStr (LPCTSTR s, LPCTSTR STR);
Long SendCommand (LPCTSTR CMD);
Long UseDict (index);
Cstrings GetBasePath ();
Long SetDictPwd (LPCTSTR PWD);
Cstrings OcrInFile (long x1, long y1, long x2, long y2, LPCTSTR pic_name, LPCTSTR color, double sim);
Long the Capture (long x1, long y1, long x2, long y2, LPCTSTR file).
Long KeyPress (long vitamin k);
Long KeyDown (long vitamin k);
Long KeyUp (long vitamin k);
Long LeftClick ();
Long RightClick ();
Long MiddleClick ();
Long LeftDoubleClick ();
Long LeftDown ();
Long LeftUp ();
Long RightDown ();
Long RightUp ();
Long MoveTo (long x, long y);
Long MoveR (long rx, long ry);
Cstrings GetColor (long x, long y);
Cstrings GetColorBGR (long x, long y);
Cstrings RGB2BGR (LPCTSTR rgb_color);
Cstrings BGR2RGB (LPCTSTR bgr_color);
Long UnBindWindow ();
Long CmpColor (long x, long y, LPCTSTR color, double sim);
Long ClientToScreen (long HWND, VARIANT * x, the VARIANT * y);
Long ScreenToClient (long HWND, VARIANT * x, the VARIANT * y);
Long ShowScrMsg (long x1, long y1, long x2, long y2, LPCTSTR MSG, LPCTSTR color);
Long SetMinRowGap (long row_gap);
Long SetMinColGap (long col_gap);
Long FindColor (long x1, long y1, long x2, long y2, LPCTSTR color, double sim, long dir, VARIANT * x, the VARIANT * y);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related