Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Createdispatch problem (PLEASE help) 1

Status
Not open for further replies.

howardnl

Programmer
Apr 12, 2001
18
0
0
US
Hello everyone,

Here is my problem. I created an exe that was basically a collection of functions and it worked fine. It created an Excel spreadsheet, put some data in cells, and saved it. It uses Createdispatch to open Excel. I wanted to move these functions to a dll, but when I call Createdispatch in the dll it doesn't work. Any help at all is greatly appreciated.

Thanks,
Nick
 
The most common problem is that you didn't initiate the COM apartment by calling
Code:
CoInitialize(NULL)
.

The DLL works into the COM apartment of the EXE file.

Test this: run the Debug version of DLL form Visual Studio environment in order to catch all TRACE messages. If
Code:
CoCreateInstance()
function fails inside
Code:
CreateDispatch()
function (a good idea is to run step by step the CreateDispatch's code) then the return code of
Code:
CoCreateInstance()
function will describe the error. The error will be dumped into debug window. I guess you will see the
Code:
CO_E_NOTINITIALIZED
error code (0x800401F0L).

Resolution: Add
Code:
CoInitialize(NULL)
/
Code:
CoUninitialize()
in your start up /end code of the EXE file which loads the DLL (
Code:
InitInstance()
/
Code:
ExitInstance()
functions).

Tip: Instead using old Dispatch wrapper classes you should use
Code:
#import
directive which works faster without Invoke.

Marius Samoila
Brainbench MVP for Visual C++
 
Thank you very much for your help. You are absolutely correct and now it works as it should. I'm kind of new to this type of stuff, so what is the #import directive and how is it used? If you know of a site with a good explannation that would be great. Any additional help is greatly appreciated. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top