vc++ api question...........

Discussion in 'SolidWorks' started by Sushil, Oct 2, 2003.

  1. Sushil

    Sushil Guest

    hello folks,

    i recently started playing with vc++ api for solidworks...

    I have VC++ version 6.0 and SolidWorks 2001 plus...

    i started with the solidworks add in app wizard which generated a
    skeleton application with a toolbar and a menu bar built in...

    i tried to build a dialog box class which can be invoked from the
    toolbar and menu...however..the application hangs..immediately when
    the dialog box appears...

    solidworks issues a message saying that solidworks has terminated due
    to an unhandled error...please contact your local support
    representative for help in troubleshooting this problem...

    can anybody please tell me what the problem could be....

    thanks in advance..

    ~sushil.
     
    Sushil, Oct 2, 2003
    #1
  2. This is a welcome message. Welcome in the wonderful world of c++ api!
    Seriously, this happens in most cases when your program crashes or does
    something wrong, you'll see it many times... What you have to do is:
    1) run your program in the Visual Studio Debugger.
    2) check the "Exceptions" under the "Debug" menu (visible only while running
    the debugger) and set at least c00000005 "Access violation" to "Stop
    Always". It might help to find what's wrong
    3) put all your code in try/catch statements to exit smoothly from your
    add-in if something goes wrong. Hopefully, SW will be able to continue after
    that.
    Good luck!
     
    Philippe Guglielmetti, Oct 2, 2003
    #2
  3. Sushil

    Pascal Scanu Guest

    Found in the MSDN Library help about AFX_MANAGE_STATE
    By default, MFC uses the resource handle of the main application to load the
    resource template. If you have an exported function in a DLL, such as one
    that launches a dialog box in the DLL, this template is actually stored in
    the DLL module. You need to switch the module state for the correct handle
    to be used. You can do this by adding the following code to the beginning of
    the function:

    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    This swaps the current module state with the state returned from
    AfxGetStaticModuleState until the end of the current scope.

    Example :
    void CTest::CreateAlias()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CDlgAlias dlg;
    dlg.DoModal();
    }

    It may correct your problem

    P. Scanu
    http://www.atemi.fr
     
    Pascal Scanu, Oct 2, 2003
    #3
  4. Sushil

    Sushil Guest

    Hi Pascal,

    I tried it out...but this is what I am getting...

    mfcs42.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined
    in Boring1.obj
    mfcs42.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already
    defined in Boring1.obj
    mfcs42.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already
    defined in Boring1.obj; second definition ignored
    mfcs42.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already
    defined in Boring1.obj; second definition ignored
    Creating library Boring1___Win32_MBCS_Release/Boring1.lib and
    object Boring1___Win32_MBCS_Release/Boring1.exp
    Boring1___Win32_MBCS_Release/Boring1.dll : fatal error LNK1169: one or
    more multiply defined symbols found
    Error executing link.exe.

    Boring1.dll - 3 error(s), 2 warning(s)

    Is there anything that I am missing again...please help me out...

    ~Sushil.
     
    Sushil, Oct 3, 2003
    #4
  5. you're linking the wrong MFC dlls.
    In project settings, C/C++ tab, select "Multithreaded DLL" under "Use
    run-time library".
    You must select this for all libs or dlls your project is using.
     
    Philippe Guglielmetti, Oct 3, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.