我正在尝试与我不想说的制造商的研究光谱仪进行交流。
制造商在 Visual C++ 6 中提供了一些 DLL 和示例项目,但显然不支持它们。我能够使用 VS 2017 和 2022 进行编译。它基于具有 ATL 支持的 MFC。但是,当根据制造商手册在 VS 2022 和 2017 中创建新项目时,具有相同的项目属性的代码在调用
CoCreateInstance
. 时确实会抛出访问冲突错误
有人知道导致问题的原因以及为什么它适用于示例代码吗?
CoCreateInstance
中的第一个 LoadMono()
工作完美,我的代码在之后的初始化中中断。 clsid
看起来不错。我认为问题与无法访问的IJYMonoReqd
有关。
下面是我的代码。为了便于阅读,我删除了大部分向导生成的代码:
// MFCAppDlg.cpp:
//
#include "pch.h"
#include "framework.h"
#include "MFCApp.h"
#include "MFCAppDlg.h"
#include "DlgProxy.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg-Dialog "Info"
class CAboutDlg : public CDialogEx
{
...
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
...
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CMFCAppDlg-MainDialog
IMPLEMENT_DYNAMIC(CMFCAppDlg, CDialogEx);
CMFCAppDlg::CMFCAppDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_MFCAPP_DIALOG, pParent)
{
..
m_jyMono = NULL;
}
CMFCAppDlg::~CMFCAppDlg()
{
...
}
void CMFCAppDlg::DoDataExchange(CDataExchange* pDX)
{
...
}
BEGIN_MESSAGE_MAP(CMFCAppDlg, CDialogEx)
...
END_MESSAGE_MAP()
BOOL CMFCAppDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
...
// TODO: Additional Init
LoadMonos();
//create an instance of the mono object
HRESULT hr = S_OK;
CLSID clsid;
if (m_jyMono == NULL)
{
hr = CLSIDFromProgID(L"JYMono.Monochromator", &clsid);
hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(IJYMonoReqd), (void**)&m_jyMono); //breaks here
if (FAILED(hr)
{
TRACE("Failed to create Mono Object. Err: %ld", hr);
return FALSE;
}
}
return TRUE;
}
...
void CMFCAppDlg::LoadMonos()
{
USES_CONVERSION;
IJYConfigBrowerInterface* pConfigBrowser;
HRESULT hr = CoCreateInstance(__uuidof(JYConfigBrowerInterface),
NULL, CLSCTX_INPROC_SERVER,
__uuidof(IJYConfigBrowerInterface),
(void**)&pConfigBrowser);
pConfigBrowser->Load();
CComBSTR name, monoID;
bool bMore = true;
int i = 0;
pConfigBrowser->GetFirstMono(&name, &monoID);
m_monoArray[i][0] = W2A(monoID);
m_monoArray[i][1] = W2A(name);
i++;
CString strName, strMonoID;
pConfigBrowser->GetNextMono(&name, &monoID);
while (true)
{
strName = W2A(name);
strMonoID = W2A(monoID);
if (strName.IsEmpty() && strMonoID.IsEmpty())
break;
m_monoArray[i][0] = strMonoID;
m_monoArray[i][1] = strName;
i++;
pConfigBrowser->GetNextMono(&name, &monoID);
}
}
和标题:
// MFCAppDlg.h: Headerfile
//
#pragma once
class CMFCAppDlgAutoProxy;
#import "C:\Program Files (x86)\Jobin Yvon\Common\JY Components\JYSupport\jysystemLib.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#import "C:\Program Files (x86)\Jobin Yvon\Common\JY Components\JYSupport\JYConfigBrowserComponent.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids
// CMFCAppDlg-Dialog
class CMFCAppDlg : public CDialogEx
{
DECLARE_DYNAMIC(CMFCAppDlg);
friend class CMFCAppDlgAutoProxy;
// Construction
public:
CMFCAppDlg(CWnd* pParent = nullptr); // Standardkonstruktor
virtual ~CMFCAppDlg();
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MFCAPP_DIALOG };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-Unterstützung
// Implementation
protected:
CMFCAppDlgAutoProxy* m_pAutoProxy;
HICON m_hIcon;
BOOL CanExit();
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnClose();
virtual void OnOK();
virtual void OnCancel();
DECLARE_MESSAGE_MAP()
private:
//Mono functions
void LoadMonos();
CString m_monoArray[10][2];
IJYMonoReqd *m_jyMono;
};
到目前为止我试过:
编辑:
调用堆栈如下所示:
02d11004() Unknown No symbols loaded.
[Frames below may be incorrect and/or missing] Annotated Frame
user32.dll!__InternalCallWinProc@20() Unknown Non-user code. Symbols loaded.
user32.dll!UserCallWinProcCheckWow() Unknown Non-user code. Symbols loaded.
user32.dll!CallWindowProcAorW(long ,struct HWND__ *,enum _WM_VALUE,unsigned int,long,int) Unknown Non-user code. Symbols loaded.
user32.dll!_CallWindowProcA@20() Unknown Non-user code. Symbols loaded.
mfc140d.dll!_AfxActivationWndProc(HWND__ * hWnd=0x000a04f0, unsigned int nMsg=129, unsigned int wParam=0, long lParam=3854696) Line 478 C++ Non-user code. Symbols loaded.
user32.dll!__InternalCallWinProc@20() Unknown Non-user code. Symbols loaded.
user32.dll!UserCallWinProcCheckWow() Unknown Non-user code. Symbols loaded.
user32.dll!DispatchClientMessage() Unknown Non-user code. Symbols loaded.
user32.dll!__fnINLPCREATESTRUCT() Unknown Non-user code. Symbols loaded.
ntdll.dll!_KiUserCallbackDispatcher@12() Unknown Non-user code. Symbols loaded.
user32.dll!CreateWindowInternal() Unknown Non-user code. Symbols loaded.
user32.dll!_CreateWindowExA@48() Unknown Non-user code. Symbols loaded.
JYMono.dll!100476c2() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!10043562() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!10042bc9() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!100fa0c0() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!100fa08b() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!10042239() Unknown Non-user code. Binary was not built with debug information.
JYMono.dll!10042443() Unknown Non-user code. Binary was not built with debug information.
combase.dll!CServerContextActivator::CreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c) Line 881 C++ Non-user code. Symbols loaded.
combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesOut * * ppActPropsOut=0x003ae52c) Line 1931 C++ Non-user code. Symbols loaded.
combase.dll!CApartmentActivator::CreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c) Line 2189 C++ Non-user code. Symbols loaded.
combase.dll!CProcessActivator::CCICallback(unsigned long dwContext=1, IUnknown * pUnkOuter=0x00000000, ActivationPropertiesIn * pActIn=0x003adcc0, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c) Line 1645 C++ Non-user code. Symbols loaded.
combase.dll!CProcessActivator::AttemptActivation(ActivationPropertiesIn * pActIn=0x003adcc0, IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c, HRESULT(__stdcallCProcessActivator::*)(unsigned long, IUnknown *, ActivationPropertiesIn *, IActivationPropertiesIn *, IActivationPropertiesOut * *) pfnCtxActCallback=0x765a0cb0, unsigned long dwContext=1) Line 1527 C++ Non-user code. Symbols loaded.
combase.dll!CProcessActivator::ActivateByContext(ActivationPropertiesIn * pActIn=0x003adcc0, IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c, HRESULT(__stdcallCProcessActivator::*)(unsigned long, IUnknown *, ActivationPropertiesIn *, IActivationPropertiesIn *, IActivationPropertiesOut * *) pfnCtxActCallback=0x765a0cb0) Line 1393 C++ Non-user code. Symbols loaded.
combase.dll!CProcessActivator::CreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c) Line 1271 C++ Non-user code. Symbols loaded.
combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesOut * * ppActPropsOut=0x003ae52c) Line 1931 C++ Non-user code. Symbols loaded.
combase.dll!CClientContextActivator::CreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesIn * pInActProperties=0x003ade94, IActivationPropertiesOut * * ppOutActProperties=0x003ae52c) Line 570 C++ Non-user code. Symbols loaded.
combase.dll!ActivationPropertiesIn::DelegateCreateInstance(IUnknown * pUnkOuter=0x00000000, IActivationPropertiesOut * * ppActPropsOut=0x003ae52c) Line 1983 C++ Non-user code. Symbols loaded.
combase.dll!ICoCreateInstanceEx(const _GUID & OriginalClsid, IUnknown * punkOuter=0x00000000, unsigned long dwClsCtx=23, _COSERVERINFO * pServerInfo=0x00000000, unsigned long dwCount=1, unsigned long dwActvFlags=0, tagMULTI_QI * pResults=0x003ae91c, ActivationPropertiesIn * pActIn=0x003adcc0) Line 2032 C++ Non-user code. Symbols loaded.
combase.dll!CComActivator::DoCreateInstance(const _GUID & Clsid={...}, IUnknown * punkOuter=0x00000000, unsigned long dwClsCtx=23, _COSERVERINFO * pServerInfo=0x00000000, unsigned long dwCount=1, tagMULTI_QI * pResults=0x003ae91c, ActivationPropertiesIn * pActIn=0x00000000) Line 401 C++ Non-user code. Symbols loaded.
[Inline Frame] combase.dll!CoCreateInstanceEx(const _GUID &) Line 177 C++ Non-user code. Symbols loaded.
combase.dll!CoCreateInstance(const _GUID & rclsid={...}, IUnknown * pUnkOuter=0x00000000, unsigned long dwContext=23, const _GUID & riid={...}, void * * ppv=0x003afa1c) Line 121 C++ Non-user code. Symbols loaded.
Example.exe!CExampleDlg::OnInitDialog() Line 134 C++ Symbols loaded.
mfc140d.dll!AfxDlgProc(HWND__ * hWnd=0x0005047a, unsigned int message=272, unsigned int __formal=66690, long __formal=0) Line 28 C++ Non-user code. Symbols loaded.
user32.dll!__InternalCallWinProc@20() Unknown Non-user code. Symbols loaded.
user32.dll!UserCallDlgProcCheckWow() Unknown Non-user code. Symbols loaded.
user32.dll!DefDlgProcWorker() Unknown Non-user code. Symbols loaded.
user32.dll!_DefDlgProcA@16() Unknown Non-user code. Symbols loaded.
user32.dll!__InternalCallWinProc@20() Unknown Non-user code. Symbols loaded.
user32.dll!UserCallWinProcCheckWow() Unknown Non-user code. Symbols loaded.
user32.dll!CallWindowProcAorW(long ,struct HWND__ *,enum _WM_VALUE,unsigned int,long,int) Unknown Non-user code. Symbols loaded.
user32.dll!_CallWindowProcA@20() Unknown Non-user code. Symbols loaded.
mfc140d.dll!CWnd::DefWindowProcA(unsigned int nMsg=272, unsigned int wParam=66690, long lParam=0) Line 1100 C++ Non-user code. Symbols loaded.
mfc140d.dll!CWnd::Default() Line 297 C++ Non-user code. Symbols loaded.
mfc140d.dll!CDialog::HandleInitDialog(unsigned int __formal=66690, long __formal=0) Line 740 C++ Non-user code. Symbols loaded.
mfc140d.dll!CWnd::OnWndMsg(unsigned int message=272, unsigned int wParam=66690, long lParam=0, long * pResult=0x003af204) Line 2441 C++ Non-user code. Symbols loaded.
mfc140d.dll!CWnd::WindowProc(unsigned int message=272, unsigned int wParam=66690, long lParam=0) Line 2099 C++ Non-user code. Symbols loaded.
mfc140d.dll!AfxCallWndProc(CWnd * pWnd=0x003af8f4, HWND__ * hWnd=0x0005047a, unsigned int nMsg=272, unsigned int wParam=66690, long lParam=0) Line 265 C++ Non-user code. Symbols loaded.
mfc140d.dll!AfxWndProc(HWND__ * hWnd=0x0005047a, unsigned int nMsg=272, unsigned int wParam=66690, long lParam=0) Line 418 C++ Non-user code. Symbols loaded.
mfc140d.dll!AfxWndProcBase(HWND__ * hWnd=0x0005047a, unsigned int nMsg=272, unsigned int wParam=66690, long lParam=0) Line 299 C++ Non-user code. Symbols loaded.
user32.dll!__InternalCallWinProc@20() Unknown Non-user code. Symbols loaded.
user32.dll!UserCallWinProcCheckWow() Unknown Non-user code. Symbols loaded.
user32.dll!SendMessageWorker(struct tagWND *,unsigned int,unsigned int,long,int) Unknown Non-user code. Symbols loaded.
user32.dll!InternalCreateDialog() Unknown Non-user code. Symbols loaded.
user32.dll!_CreateDialogIndirectParamAorW@24() Unknown Non-user code. Symbols loaded.
user32.dll!_CreateDialogIndirectParamA@20() Unknown Non-user code. Symbols loaded.
mfc140d.dll!IsolationAwareCreateDialogIndirectParamA(HINSTANCE__ * hInstance=0x007c0000, const DLGTEMPLATE * lpTemplate=0x0080ee70, HWND__ * hWndParent=0x00000000, int(__stdcall*)(HWND__ *, unsigned int, unsigned int, long) lpDialogFunc=0x5979ead0, long dwInitParam=0) Line 539 C++ Non-user code. Symbols loaded.
mfc140d.dll!CWnd::CreateDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x0080ee70, CWnd * pParentWnd=0x00000000, HINSTANCE__ * hInst=0x007c0000) Line 373 C++ Non-user code. Symbols loaded.
mfc140d.dll!CWnd::CreateRunDlgIndirect(const DLGTEMPLATE * lpDialogTemplate=0x0080ee70, CWnd * pParentWnd=0x00000000, HINSTANCE__ * hInst=0x007c0000) Line 475 C++ Non-user code. Symbols loaded.
mfc140d.dll!CDialog::DoModal() Line 652 C++ Non-user code. Symbols loaded.
Example.exe!CExampleApp::InitInstance() Line 126 C++ Symbols loaded.
mfc140d.dll!AfxWinMain(HINSTANCE__ * hInstance=0x007c0000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00614740, int nCmdShow=10) Line 37 C++ Non-user code. Symbols loaded.
Example.exe!WinMain(HINSTANCE__ * hInstance=0x007c0000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00614740, int nCmdShow=10) Line 26 C++ Symbols loaded.
Example.exe!invoke_main() Line 107 C++ Non-user code. Symbols loaded.
Example.exe!__scrt_common_main_seh() Line 288 C++ Non-user code. Symbols loaded.
Example.exe!__scrt_common_main() Line 331 C++ Non-user code. Symbols loaded.
Example.exe!WinMainCRTStartup() Line 17 C++ Non-user code. Symbols loaded.
kernel32.dll!@BaseThreadInitThunk@12() Unknown Non-user code. Symbols loaded.
ntdll.dll!__RtlUserThreadStart() Unknown Non-user code. Symbols loaded.
ntdll.dll!__RtlUserThreadStart@8() Unknown Non-user code. Symbols loaded.
@IInspectable:
CLSIDFromProgID
似乎有效并返回S_OK