locked
Dll related problem RRS feed

  • Question

  • Hi There ,

    I am stuck with a problem since weeks. Please help me how to call the functions defined in the dll in my c++ Unit test project in visual studio 2005. The .h file iam including has exported some apis, but still iam unable to call them in unittest.cpp . I have added a reference to the dll ,while i am able to compile the code without errors , when I run debug the tests the code for function is unavailable and i get an error which says "system.accessviolationexception: attempted to read or write protected memory. this is often an indication that other memory is corrupt.."

    I am pasting parts of the .h file here , i am not sure whether the functions i am calling are exported, I am calling

    fnitmEntitlementWrapper_ENTITLE_INST_FIRSTPlease help me solve this.

    //.h file begin

    #ifdef

    ITMENTITLEMENTWRAPPER_EXPORTS

    #define

    ITMENTITLEMENTWRAPPER_API __declspec(dllexport)

    #else

    #define ITMENTITLEMENTWRAPPER_API __declspec(dllimport)

    #endif

    // This class is exported from the itmEntitlementWrapper.dll

    class

    ITMENTITLEMENTWRAPPER_API CitmEntitlementWrapper {

    public

    :

    CitmEntitlementWrapper(

    void);

    // TODO: add your methods here.

    };

    extern

    ITMENTITLEMENTWRAPPER_API int nitmEntitlementWrapper;

    /**

    */

    ITMENTITLEMENTWRAPPER_API EINSTALLTYPE fnGetInstallType(

    const wchar_t * InstallType);

    ITMENTITLEMENTWRAPPER_API

    int vm_wstrcmp(const wchar_t* s1, const wchar_t* s2);

    extern

    "C"

    {

    /**

    * fnitmEntitlementWrapper_ENTITLE_INST_FIRST - The purpose of this method is to load the caEntitlement.dll,

    * and this is the first method which should be called when using the caEntitlement.dll

    */

    ITMENTITLEMENTWRAPPER_API BOOL fnitmEntitlementWrapper_ENTITLE_INST_FIRST(

    const wchar_t *eProductID = L"eProductNone",

    const wchar_t *ePackageID = L"ePackageNone", HWND hWndParent = NULL);

    //.h file end

    Thanks

    Deah

    Tuesday, November 8, 2011 7:21 AM

All replies

  •  Hi,

     

    “System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..”

     

    If you have VS2005 C++ Unit Tests, written in managed C++ as they should be, and you are calling native code from them, and you see that error when running your unit tests. It means that you are using insecure versions of methods (strcpy, etc). If you change the method calls to the secure versions, you should see your tests pass.

     

    Fan


    When you help others, it's help yourself!
    Thursday, November 10, 2011 5:43 AM
  • Hi,
     
    Welcome to the MSDN Forum.
     
    According to your description, I'd like to move your thread to "Visual Studio Unit Testing" forum where you will get better support.
     
    Thank you for your understanding.
    Best regards,

    Helen Zhao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 10, 2011 6:11 AM