weixin_44797823
穹涯
采纳率33.3%
2019-04-21 10:50

0x00000000 处的第一机会异常(在 LOAD_WIZARD.exe 中): 0xC0000005: 执行位置 0x00000000 时发生访问冲突

5
  • c++
  • visual studio

VS2012编译能够成功,但是在调用的时候出现了上述问题问题,请各位指点。运行的时候一直到printf那里都是没有问题的。

调用的代码如下

#include "stdafx.h"
#include <stdio.h>

#include <windows.h>


typedef void(*MAINFUNCTION)(int Type, const char *HandleNum, const char *MiddleNum, const char *PoleNum, const char *BladeNum);

int _tmain(int argc, _TCHAR* argv[])
{
    HMODULE hModule1  = GetModuleHandle(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\NX10_NXOpenCPP_Wizard1.dll");

    if (NULL == hModule1)
    {
        hModule1 = LoadLibraryEx(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\tool_assenbal_external.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
        //hModule1 = LoadLibrary(L"D:\\Program Files\\Siemens\\NX 10.0\\UGII\\NX10_NXOpenCPP_Wizard1.dll");
    }   

    MAINFUNCTION Mainfunction = (MAINFUNCTION)GetProcAddress(hModule1, "Mainfunction");

    const char *HandleNum2 = "BT40-ER32-70";
    const char *MiddleNum2 = "ER32-12";
    const char *PoleNum2 = "D10";
    const char *BladeNum2 = "";
    printf("测试代码1!");
    Mainfunction(2, HandleNum2, MiddleNum2, PoleNum2, BladeNum2);

    FreeLibrary(hModule1);
    getchar();

    return 0;
}

函数体如下

extern "C" DllExport void Mainfunction(int Type, const char *HandleNum, const char *MiddleNum, const char *PoleNum, const char *BladeNum)       
{
    //以下为用户代码
        Handle = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀柄库\\";
        Middle = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\夹套库\\";
        Pole = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀杆库\\";
        Blade = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\刀片库\\";
        HandleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\HandleBase.dat";
        MiddleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\MiddleBase.dat";
        PoleBase = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\PoleBase.dat";
        CompletePath = "D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\ToolBase\\整刀库\\";

    if( UF_CALL(UF_initialize()) ) 
    {
        /* Failed to initialize */

        return ;
    }
    printf("开始导入!\n");

    //新建一个prt
    tag_t PartTAG = NULL_TAG;
    UF_CALL(UF_PART_new("D:\\Program Files\\Siemens\\NX 10.0\\SECONDARY_DEVELOPMENT\\DateBase\\Temp\\Test.prt", UF_PART_METRIC, &PartTAG));

    char ToolPath[255];
    if (1 == Type)
    {
        ImportHandle(HandleNum);
        sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", BladeNum, ".prt");
    }
    else if (2 == Type)
    {
        ImportHandle(HandleNum);
        ImportMiddle(MiddleNum);
        ImportPole(PoleNum);
        sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", MiddleNum, "+", PoleNum,".prt");
    }
    else
    {
        ImportHandle(HandleNum);
        ImportMiddle(MiddleNum);
        ImportPole(PoleNum);
        sprintf_s(ToolPath, "%s",CompletePath, HandleNum, "+", MiddleNum, "+", PoleNum, BladeNum, ".prt");  
    }

    printf("导入完成!\n");
    UF_CALL(UF_PART_save_as(ToolPath));
    UF_CALL(UF_PART_close(PartTAG, 0, 1));
    UF_CALL(UF_terminate());


    return ;
}


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dabocaiqq dabocaiqq 2年前

    这个需要调试了才知道,但是你声望0,采纳率0。可不敢白费力气。

    点赞 评论 复制链接分享