CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Location
    Austin, TX
    Posts
    24

    [RESOLVED] Weird CoCreateInstance error

    Hi everyone!

    I'm writing a data conversion program for my company. I have an ActiveX DLL that was written in VB6, which I know works. I'm writing the interface in Win32 API/C++ because I want to use the CreateThread API to run the data conversion in (it's a long process). I already have my interface written, but my problem comes when I try to use my DLL in my C++ project.

    1. I know for a fact the DLL is registered.
    2. I used OLE View after registering the DLL to get the IDL file information, and ran midl on it to get my header file and C file.
    3. I've imported these into my project and #included the header file in my main .cpp file.

    Here's the offending code:

    Technical:
    //initialize my COM dll
    _DBWorker *dbw = NULL;
    HRESULT hr;

    hr = CoInitialize(0);

    if(SUCCEEDED(hr)) {
    hr = CoCreateInstance(CLSID_DBWorker, NULL, CLSCTX_INPROC_SERVER, IID__DBWorker, (void**) &dbw);
    if(FAILED(hr)) {
    _com_error err(hr);
    MessageBox(NULL, err.ErrorMessage(), "error", MB_OK);
    CoUninitialize();
    return(0);
    }
    }


    The _com_error returns 0x800A0036, which I have found out to be a CTL_E_BADFILEMODE error. Further Google-ing has not clued me in to why this error is being given.

    Thank you for any help

  2. #2
    Join Date
    May 2004
    Location
    London, England
    Posts
    563

    Re: Weird CoCreateInstance error

    well, 'googling' has informed me that maybe you are opening a file using an incorrect mode. Valid modes are :

    Append,
    Binary,
    Input,
    Output, or
    Random.



    Regards

    John
    I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)

  3. #3
    Join Date
    Apr 2006
    Location
    Austin, TX
    Posts
    24

    Resolved Re: Weird CoCreateInstance error

    Quote Originally Posted by Vaderman
    well, 'googling' has informed me that maybe you are opening a file using an incorrect mode. Valid modes are :

    Append,
    Binary,
    Input,
    Output, or
    Random.

    Wow, it's Tuesday and I'm having a case of the Mondays! I almost feel silly now, I'll check on that. Thanks

  4. #4
    Join Date
    Apr 2006
    Location
    Austin, TX
    Posts
    24

    Talking Re: Weird CoCreateInstance error

    HA! Boy I feel really silly now...

    CoCreateInstance did in fact create an instance of my DLL, the error was originating from the Class_Initialize sub in my class. I have a log file that I write to during various important steps in the conversion process. I was opening it with a FileSystemObject as read-only, and then I tried to write to it :P

    What kills me is that I'd been stumped on this for almost two days. I got a good laugh out of that one, hehe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured