打开simul8文件时出现错误
Getting Error on opening simul8 file
我想使用c++打开simul8文件,我已经做了以下操作
#include "stdafx.h"
#include "windows.h"
#import "C:Program FilesSIMUL8S8.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 FilesSIMUL8S8.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 Demo正在运行:-)
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 打开simul8文件时出现错误