gpt4 book ai didi

c++ - 打开 simul8 文件时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:58:24 24 4
gpt4 key购买 nike

我想用 C++ 打开 simul8 文件我做了以下操作

#include "stdafx.h"
#include "windows.h"
#import "C:\Program Files\SIMUL8\S8.exe" named_guids
using namespace SIMUL8;

int _tmain(int argc, _TCHAR* argv[])
{

IS8Simulation* MYSIMUL8 = NULL;
IUnknown* pUnk = NULL;
HRESULT hr = ::CoCreateInstance(SIMUL8::CLSID_S8Simulation,NULL,CLSCTX_ALL,__uuidof(IUnknown),(void**)&pUnk);
_bstr_t bstrFileName = ::SysAllocString(L"D:\\Demo1.s8");

hr = MYSIMUL8->Open(bstrFileName);
MYSIMUL8->RunSim(2400);
}

我在 SimTest.exe 中的 0x004017e7 处收到错误消息未处理的异常:0xC0000005:访问冲突读取位置 0x00000000。在 s8.tli 中

inline HRESULT IS8Simulation::Open ( _bstr_t FileName ) {
HRESULT _hr = raw_Open(FileName); ON THIS LINE
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
}

请帮助我,我做错了什么

最佳答案

我已经解决了这个问题。错误是我没有初始化 COM 对象我已经修改了代码如下...

// SimTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#import "C:\Program Files\SIMUL8\S8.exe" named_guids
using namespace SIMUL8;

int _tmain(int argc, _TCHAR* argv[])
{
//Simul8.Simulation8 *pObject;
IS8Simulation * MYSIMUL8;
MYSIMUL8=(struct IS8Simulation *) malloc(sizeof(struct IS8Simulation ));


IUnknown * pUnk ;

CoInitialize( NULL );
HRESULT hr = ::CoCreateInstance(SIMUL8::CLSID_S8Simulation ,NULL,CLSCTX_ALL,__uuidof(IUnknown),(void**)&pUnk);


hr = pUnk->QueryInterface(__uuidof(IS8Simulation), (void**)&MYSIMUL8);

_bstr_t bstrFileName = ::SysAllocString(L"D:\\Demo1.s8");


MYSIMUL8->Open(bstrFileName);
MYSIMUL8->Visible = true;
MYSIMUL8->RunSim(2400);



// Uninitialize COM.
//CoUninitialize();
}

现在我的 Simul8 演示正在运行 :-)

关于c++ - 打开 simul8 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14068385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com