CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Posts
    1

    DLL, #import and ADO. HELP needed!

    Hi,
    I am learning c++/ado(Migrating from VB to VC++). However, I am encountering a strange error that I can't figure out. I wrote a little ado function and call it in a test app. Everything works. I then migrate the funtion to a dll and execute it. However, the dll will just hang/die at the open method. The ado codes are identical in both cases. There is no error in the dll itself since everything else execute without an error. The dll hang exactly at the Open command. I try to catch the error by using try/catch to get a error number and description. However, no such luck since the dll never return anything. I know it dies at the open command since i got the "opening db" message but not the message "open command done" afterward the open command. Below is the code I use to test the function. I will appreciate any help or hint regarding this.

    #import "c:\program files\common files\system\ado\msado15.dll" rename "EOF", "adoEOF" )

    struct InitOle {
    InitOle() { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize(); }
    } _init_InitOle_;

    void test()
    {
    HRESULT hr;
    _ConnectionPtr PCon;
    _RecordsetPtr Rst;
    try{
    hr = PCon.CreateInstance(__uuidof(Connection));
    if (SUCCEEDED(hr)){
    MessageBox(NULL, "openning db", "", MB_OK);
    hr = PCon->Open(_bstr_t("DSN=test;UID=test;PWD=;"), _bstr_t(""), _bstr_t(""), adModeUnknown);
    MessageBox(NULL, "open command done", "", MB_OK);
    if (SUCCEEDED(hr)){MessageBox(NULL, "open okay", "", MB_OK);}}
    catch (_com_error& e){
    MessageBox(NULL, e.ErrorMessage(), "", MB_OK);
    MessageBox(NULL, e.Description(), "", MB_OK);}
    }

    Regads,
    Hung


  2. #2
    Guest

    Re: DLL, #import and ADO. HELP needed!

    Hi, I'm waiting for my password, therefore i reply under anonymous.
    Check out your DSN. I don't know the Database you use. Try out UID=sa,PWD=''.
    Then you can try this code:
    HRESULT hr = S_OK;
    hr=::CoInitialize(NULL);
    _bstr_t m_strConn;
    m_strConn = <Your Connection String> ;
    PCon.CreateInstance(__uuidof(Connection));
    PCon->CursorLocation = adUseClient;
    PCon->Open(m_strConn, "", "", NULL);

    We use ADO in a shared MFC DLL and it works

    Hope, I could help you.
    Bene


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