Link to home
Start Free TrialLog in
Avatar of shala
shala

asked on

How to use CoCreateInstanceEx?

In vc6.0,I write a CoCreateInstanceEx call,but when I compile the project,it show:"error C2065: 'CoCreateInstanceEx' : undeclared identifier",How should I do?
Avatar of WxW
WxW

Include ole2.h or windows.h or richole.h
I'm sure he is.

This function was added for win95 and NT 4, so it is not part of the original win32 API.  so it is recognized only if you have the _WIN32_WINNT #defined as >= 0x04000.  (indicating a Win NT 4.0) target.  Or if you have #defined _WIN32_DCOM

Let me know if you have any questions.
Avatar of shala

ASKER

I try,but still fail.
You tried what?   Did you set the target version number, like I suggested?
The CoCreateInstance is declared in the <objbase.h> file.
BUT: The easiest is to write it in one of the following:

In an MFC AppWizard Dialog Based Exe:
Inside the ...Dlg.cpp file, after
CoInitialize(NULL);

Or:
In an MFC AppWizard SDI/MDI based Exe:
In the ...Doc.cpp file.

Or:
In an ATL AppWizard COM Exe or DLL.

In all cases the CoCreateInstance is declared in the "stdAfx.h" file which calls the <atlbase.h> or the <afxdisp>
or the <afxcomn.h>.

You should not attempt to do these manually.
One thing that happens many times is the place you put some .h files inside your code. Play around with the order of your header files.
If it doesn't help would you like to send the code?
Avatar of shala

ASKER

I tried:
# include <ole2.h> or <windows.h> or <richole.h>

or

#define _WIN32_WINNT 0x04000
 
but lost.

I just want to create a remote object(a Activex EXE on different machine), have a sample method?
also add the
#define _WIN32_DCOM

AND take a look at the example at
http://journal.iftech.com/articles/dcom_3/
Scroll down to the "client code" and click: "view client code".
There's nothing special in the example, except that it's a console app, and added the _WIN32_DCOM in the stdafx.h file.

What version of VStudio are you working with?

Good luck, Moshe
Avatar of shala

ASKER

Now in vc++6.0,I added the _WIN32_DCOM in the stdafx.h file,and copy the example code,but fail in:
#include "RemoteServer.h"
#include "RemoteServer_i.c"

I don't have the two files,I only have a exe file(activex exe writed by vb),how to create the two files?
Avatar of shala

ASKER

I want to see other answers.
Hi sala,

You don't need the _i.c and the .h if your are using smartpointers!
The smartpointer comes from the .exe .dll or .ocx via the #import directive.

You can also use the "Insert ActiveX component" in your MFC Appwizard Exe project. Simply Right Mouse Button on the dialog you are developing (in the resource view after double clicking the resources/dialog/IDD_MYPROJ_DIALOG, and "Insert ActiveX component".

Or you can use the menu: project/add to project/components and controls
And add your item to the project.
Then use it from the toolbar. (along with buttons edit boxes and other controls, you have your new control, drag onto your dialog, and work with it.)

Good luck, Moshe
ASKER CERTIFIED SOLUTION
Avatar of ajitm
ajitm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial