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?
shalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WxWCommented:
Include ole2.h or windows.h or richole.h
0
nietodCommented:
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.
0
shalaAuthor Commented:
I try,but still fail.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

nietodCommented:
You tried what?   Did you set the target version number, like I suggested?
0
mflamCommented:
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?
0
shalaAuthor Commented:
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?
0
mflamCommented:
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
0
shalaAuthor Commented:
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?
0
shalaAuthor Commented:
I want to see other answers.
0
mflamCommented:
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
0
ajitmCommented:
Pl. check the following:
1. At the start of the code use
CoInitialize(NULL);
2. Include header objbase.h.
3. Instead of directly using the function use with double scope resolution. i.e.
::CoCreateInstanceEx( ... );

4. Ensure the OS is NT 4.0 or later OR
Windows95 or later.

Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.