How to fix CoCreateInstance read access violation?












1














I used the C++ MFC activex script to call the javascript function,
which compiles normally but uses the init function to run to CoCreateInstance, causing a read access violation(this 0x4).
How to solve this problem?



Below is my code:



// BasicScriptHost.cpp



#include "stdafx.h"
#include "DTCfg.h"
#include "BasicScriptHost.h"
#include <atlbase.h>
#include <string>
#include <atlfile.h>
using namespace std;

HRESULT BasicScriptHost::Init() {
CLSID clsJS;
HRESULT hr = ::CLSIDFromProgID(L"javascript", &clsJS);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER,
IID_IActiveScript, (void**)&m_pEngine);//Error read access violation
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine.QueryInterface(&m_pEngineParse);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngineParse->InitNew();
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptSite(this);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_STARTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

return S_OK;
}

HRESULT BasicScriptHost::Close()
{
HRESULT hr = m_pEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CLOSED);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::AddScriptFile(string const& file)
{
CAtlFile atlfile;
HRESULT hr = atlfile.Create((LPCTSTR)file.c_str(), GENERIC_READ, 0,
OPEN_EXISTING);
if (FAILED(hr))
{
return SETERROR(hr);
}

ULONGLONG len;
hr = atlfile.GetSize(len);
if (FAILED(hr))
{
return SETERROR(hr);
}

LARGE_INTEGER li;
li.QuadPart = len;
CAutoVectorPtr<char> szData(new char[li.LowPart + 1]);
if (!szData)
{
return SETERROR(E_OUTOFMEMORY);
}

DWORD dwBytesRead;
hr = atlfile.Read(szData, li.LowPart, dwBytesRead);
if (FAILED(hr))
{
return SETERROR(hr);
}

szData[dwBytesRead] = '';
atlfile.Close(); USES_CONVERSION;
wstring script = A2W(szData); EXCEPINFO sEx;
hr = m_pEngineParse->ParseScriptText(script.c_str(), NULL, NULL,
NULL,
1, 0, SCRIPTTEXT_ISVISIBLE | SCRIPTTEXT_ISPERSISTENT, NULL,
&sEx);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::GetScriptDispatch(IDispatch** retval)
{
HRESULT hr = m_pEngine->GetScriptDispatch(NULL, retval);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}


// BasicScriptHost.h



#define SETERROR(hr) hr
#include <string>
#include <vector>
#include <activscp.h>
#include <comdef.h>
#include <atlbase.h>

class BasicScriptHost : public IActiveScriptSite
{

// IActiveScriptSite
STDMETHOD(GetItemInfo)(LPCOLESTR /*pstrName*/, DWORD
/*dwReturnMask*/,
IUnknown **ppiunkItem, ITypeInfo **ppti)
{
*ppiunkItem = NULL;
*ppti = NULL;
return S_OK;
}

STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror)
{
return S_OK;
}

STDMETHOD(GetLCID)(LCID *plcid)
{
*plcid = NULL;
return E_NOTIMPL;
}

STDMETHOD(GetDocVersionString)(BSTR* pbstrVersion)
{
*pbstrVersion = NULL;
return E_NOTIMPL;
}

STDMETHOD(OnScriptTerminate)(const VARIANT * /*pvr*/, const EXCEPINFO
* /*pei*/)
{
return S_OK;
}

STDMETHOD(OnStateChange)(SCRIPTSTATE /*ssScriptState*/)
{
return S_OK;
}

STDMETHOD(OnEnterScript)()
{
return S_OK;
}

STDMETHOD(OnLeaveScript)()
{
return S_OK;
}

public:
HRESULT Init();

HRESULT Close();

HRESULT AddScriptFile(std::string const& file);

HRESULT GetScriptDispatch(IDispatch** retval);

private:
// Script Engine Wrapper Interfaces
CComPtr<IActiveScript> m_pEngine;
CComPtr<IActiveScriptParse> m_pEngineParse;
};


//Call function part



::CoInitialize(NULL);

BasicScriptHost* host=NULL;

host->AddScriptFile("C:\Users\123.js");
host->Init();

CComPtr<IDispatch> pJs;
host->GetScriptDispatch(&pJs);
CComVariant var1(10);
CComVariant var2(20);
CComVariant ret;
pJs.Invoke2((LPCOLESTR)"add", &var1, &var2, &ret);
host->Close();
::CoUninitialize();


I think this may be because m_pEngine is invalid, but I don't know how to initialize m_pEngine.










share|improve this question









New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
    – tunglt
    20 hours ago












  • @tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
    – Bathy
    6 hours ago


















1














I used the C++ MFC activex script to call the javascript function,
which compiles normally but uses the init function to run to CoCreateInstance, causing a read access violation(this 0x4).
How to solve this problem?



Below is my code:



// BasicScriptHost.cpp



#include "stdafx.h"
#include "DTCfg.h"
#include "BasicScriptHost.h"
#include <atlbase.h>
#include <string>
#include <atlfile.h>
using namespace std;

HRESULT BasicScriptHost::Init() {
CLSID clsJS;
HRESULT hr = ::CLSIDFromProgID(L"javascript", &clsJS);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER,
IID_IActiveScript, (void**)&m_pEngine);//Error read access violation
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine.QueryInterface(&m_pEngineParse);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngineParse->InitNew();
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptSite(this);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_STARTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

return S_OK;
}

HRESULT BasicScriptHost::Close()
{
HRESULT hr = m_pEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CLOSED);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::AddScriptFile(string const& file)
{
CAtlFile atlfile;
HRESULT hr = atlfile.Create((LPCTSTR)file.c_str(), GENERIC_READ, 0,
OPEN_EXISTING);
if (FAILED(hr))
{
return SETERROR(hr);
}

ULONGLONG len;
hr = atlfile.GetSize(len);
if (FAILED(hr))
{
return SETERROR(hr);
}

LARGE_INTEGER li;
li.QuadPart = len;
CAutoVectorPtr<char> szData(new char[li.LowPart + 1]);
if (!szData)
{
return SETERROR(E_OUTOFMEMORY);
}

DWORD dwBytesRead;
hr = atlfile.Read(szData, li.LowPart, dwBytesRead);
if (FAILED(hr))
{
return SETERROR(hr);
}

szData[dwBytesRead] = '';
atlfile.Close(); USES_CONVERSION;
wstring script = A2W(szData); EXCEPINFO sEx;
hr = m_pEngineParse->ParseScriptText(script.c_str(), NULL, NULL,
NULL,
1, 0, SCRIPTTEXT_ISVISIBLE | SCRIPTTEXT_ISPERSISTENT, NULL,
&sEx);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::GetScriptDispatch(IDispatch** retval)
{
HRESULT hr = m_pEngine->GetScriptDispatch(NULL, retval);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}


// BasicScriptHost.h



#define SETERROR(hr) hr
#include <string>
#include <vector>
#include <activscp.h>
#include <comdef.h>
#include <atlbase.h>

class BasicScriptHost : public IActiveScriptSite
{

// IActiveScriptSite
STDMETHOD(GetItemInfo)(LPCOLESTR /*pstrName*/, DWORD
/*dwReturnMask*/,
IUnknown **ppiunkItem, ITypeInfo **ppti)
{
*ppiunkItem = NULL;
*ppti = NULL;
return S_OK;
}

STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror)
{
return S_OK;
}

STDMETHOD(GetLCID)(LCID *plcid)
{
*plcid = NULL;
return E_NOTIMPL;
}

STDMETHOD(GetDocVersionString)(BSTR* pbstrVersion)
{
*pbstrVersion = NULL;
return E_NOTIMPL;
}

STDMETHOD(OnScriptTerminate)(const VARIANT * /*pvr*/, const EXCEPINFO
* /*pei*/)
{
return S_OK;
}

STDMETHOD(OnStateChange)(SCRIPTSTATE /*ssScriptState*/)
{
return S_OK;
}

STDMETHOD(OnEnterScript)()
{
return S_OK;
}

STDMETHOD(OnLeaveScript)()
{
return S_OK;
}

public:
HRESULT Init();

HRESULT Close();

HRESULT AddScriptFile(std::string const& file);

HRESULT GetScriptDispatch(IDispatch** retval);

private:
// Script Engine Wrapper Interfaces
CComPtr<IActiveScript> m_pEngine;
CComPtr<IActiveScriptParse> m_pEngineParse;
};


//Call function part



::CoInitialize(NULL);

BasicScriptHost* host=NULL;

host->AddScriptFile("C:\Users\123.js");
host->Init();

CComPtr<IDispatch> pJs;
host->GetScriptDispatch(&pJs);
CComVariant var1(10);
CComVariant var2(20);
CComVariant ret;
pJs.Invoke2((LPCOLESTR)"add", &var1, &var2, &ret);
host->Close();
::CoUninitialize();


I think this may be because m_pEngine is invalid, but I don't know how to initialize m_pEngine.










share|improve this question









New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
    – tunglt
    20 hours ago












  • @tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
    – Bathy
    6 hours ago
















1












1








1







I used the C++ MFC activex script to call the javascript function,
which compiles normally but uses the init function to run to CoCreateInstance, causing a read access violation(this 0x4).
How to solve this problem?



Below is my code:



// BasicScriptHost.cpp



#include "stdafx.h"
#include "DTCfg.h"
#include "BasicScriptHost.h"
#include <atlbase.h>
#include <string>
#include <atlfile.h>
using namespace std;

HRESULT BasicScriptHost::Init() {
CLSID clsJS;
HRESULT hr = ::CLSIDFromProgID(L"javascript", &clsJS);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER,
IID_IActiveScript, (void**)&m_pEngine);//Error read access violation
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine.QueryInterface(&m_pEngineParse);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngineParse->InitNew();
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptSite(this);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_STARTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

return S_OK;
}

HRESULT BasicScriptHost::Close()
{
HRESULT hr = m_pEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CLOSED);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::AddScriptFile(string const& file)
{
CAtlFile atlfile;
HRESULT hr = atlfile.Create((LPCTSTR)file.c_str(), GENERIC_READ, 0,
OPEN_EXISTING);
if (FAILED(hr))
{
return SETERROR(hr);
}

ULONGLONG len;
hr = atlfile.GetSize(len);
if (FAILED(hr))
{
return SETERROR(hr);
}

LARGE_INTEGER li;
li.QuadPart = len;
CAutoVectorPtr<char> szData(new char[li.LowPart + 1]);
if (!szData)
{
return SETERROR(E_OUTOFMEMORY);
}

DWORD dwBytesRead;
hr = atlfile.Read(szData, li.LowPart, dwBytesRead);
if (FAILED(hr))
{
return SETERROR(hr);
}

szData[dwBytesRead] = '';
atlfile.Close(); USES_CONVERSION;
wstring script = A2W(szData); EXCEPINFO sEx;
hr = m_pEngineParse->ParseScriptText(script.c_str(), NULL, NULL,
NULL,
1, 0, SCRIPTTEXT_ISVISIBLE | SCRIPTTEXT_ISPERSISTENT, NULL,
&sEx);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::GetScriptDispatch(IDispatch** retval)
{
HRESULT hr = m_pEngine->GetScriptDispatch(NULL, retval);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}


// BasicScriptHost.h



#define SETERROR(hr) hr
#include <string>
#include <vector>
#include <activscp.h>
#include <comdef.h>
#include <atlbase.h>

class BasicScriptHost : public IActiveScriptSite
{

// IActiveScriptSite
STDMETHOD(GetItemInfo)(LPCOLESTR /*pstrName*/, DWORD
/*dwReturnMask*/,
IUnknown **ppiunkItem, ITypeInfo **ppti)
{
*ppiunkItem = NULL;
*ppti = NULL;
return S_OK;
}

STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror)
{
return S_OK;
}

STDMETHOD(GetLCID)(LCID *plcid)
{
*plcid = NULL;
return E_NOTIMPL;
}

STDMETHOD(GetDocVersionString)(BSTR* pbstrVersion)
{
*pbstrVersion = NULL;
return E_NOTIMPL;
}

STDMETHOD(OnScriptTerminate)(const VARIANT * /*pvr*/, const EXCEPINFO
* /*pei*/)
{
return S_OK;
}

STDMETHOD(OnStateChange)(SCRIPTSTATE /*ssScriptState*/)
{
return S_OK;
}

STDMETHOD(OnEnterScript)()
{
return S_OK;
}

STDMETHOD(OnLeaveScript)()
{
return S_OK;
}

public:
HRESULT Init();

HRESULT Close();

HRESULT AddScriptFile(std::string const& file);

HRESULT GetScriptDispatch(IDispatch** retval);

private:
// Script Engine Wrapper Interfaces
CComPtr<IActiveScript> m_pEngine;
CComPtr<IActiveScriptParse> m_pEngineParse;
};


//Call function part



::CoInitialize(NULL);

BasicScriptHost* host=NULL;

host->AddScriptFile("C:\Users\123.js");
host->Init();

CComPtr<IDispatch> pJs;
host->GetScriptDispatch(&pJs);
CComVariant var1(10);
CComVariant var2(20);
CComVariant ret;
pJs.Invoke2((LPCOLESTR)"add", &var1, &var2, &ret);
host->Close();
::CoUninitialize();


I think this may be because m_pEngine is invalid, but I don't know how to initialize m_pEngine.










share|improve this question









New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I used the C++ MFC activex script to call the javascript function,
which compiles normally but uses the init function to run to CoCreateInstance, causing a read access violation(this 0x4).
How to solve this problem?



Below is my code:



// BasicScriptHost.cpp



#include "stdafx.h"
#include "DTCfg.h"
#include "BasicScriptHost.h"
#include <atlbase.h>
#include <string>
#include <atlfile.h>
using namespace std;

HRESULT BasicScriptHost::Init() {
CLSID clsJS;
HRESULT hr = ::CLSIDFromProgID(L"javascript", &clsJS);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER,
IID_IActiveScript, (void**)&m_pEngine);//Error read access violation
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine.QueryInterface(&m_pEngineParse);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngineParse->InitNew();
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptSite(this);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_STARTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

return S_OK;
}

HRESULT BasicScriptHost::Close()
{
HRESULT hr = m_pEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);
if (FAILED(hr))
{
return SETERROR(hr);
}

hr = m_pEngine->SetScriptState(SCRIPTSTATE_CLOSED);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::AddScriptFile(string const& file)
{
CAtlFile atlfile;
HRESULT hr = atlfile.Create((LPCTSTR)file.c_str(), GENERIC_READ, 0,
OPEN_EXISTING);
if (FAILED(hr))
{
return SETERROR(hr);
}

ULONGLONG len;
hr = atlfile.GetSize(len);
if (FAILED(hr))
{
return SETERROR(hr);
}

LARGE_INTEGER li;
li.QuadPart = len;
CAutoVectorPtr<char> szData(new char[li.LowPart + 1]);
if (!szData)
{
return SETERROR(E_OUTOFMEMORY);
}

DWORD dwBytesRead;
hr = atlfile.Read(szData, li.LowPart, dwBytesRead);
if (FAILED(hr))
{
return SETERROR(hr);
}

szData[dwBytesRead] = '';
atlfile.Close(); USES_CONVERSION;
wstring script = A2W(szData); EXCEPINFO sEx;
hr = m_pEngineParse->ParseScriptText(script.c_str(), NULL, NULL,
NULL,
1, 0, SCRIPTTEXT_ISVISIBLE | SCRIPTTEXT_ISPERSISTENT, NULL,
&sEx);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}

HRESULT BasicScriptHost::GetScriptDispatch(IDispatch** retval)
{
HRESULT hr = m_pEngine->GetScriptDispatch(NULL, retval);
if (FAILED(hr))
{
return SETERROR(hr);
}
return S_OK;
}


// BasicScriptHost.h



#define SETERROR(hr) hr
#include <string>
#include <vector>
#include <activscp.h>
#include <comdef.h>
#include <atlbase.h>

class BasicScriptHost : public IActiveScriptSite
{

// IActiveScriptSite
STDMETHOD(GetItemInfo)(LPCOLESTR /*pstrName*/, DWORD
/*dwReturnMask*/,
IUnknown **ppiunkItem, ITypeInfo **ppti)
{
*ppiunkItem = NULL;
*ppti = NULL;
return S_OK;
}

STDMETHOD(OnScriptError)(IActiveScriptError *pscripterror)
{
return S_OK;
}

STDMETHOD(GetLCID)(LCID *plcid)
{
*plcid = NULL;
return E_NOTIMPL;
}

STDMETHOD(GetDocVersionString)(BSTR* pbstrVersion)
{
*pbstrVersion = NULL;
return E_NOTIMPL;
}

STDMETHOD(OnScriptTerminate)(const VARIANT * /*pvr*/, const EXCEPINFO
* /*pei*/)
{
return S_OK;
}

STDMETHOD(OnStateChange)(SCRIPTSTATE /*ssScriptState*/)
{
return S_OK;
}

STDMETHOD(OnEnterScript)()
{
return S_OK;
}

STDMETHOD(OnLeaveScript)()
{
return S_OK;
}

public:
HRESULT Init();

HRESULT Close();

HRESULT AddScriptFile(std::string const& file);

HRESULT GetScriptDispatch(IDispatch** retval);

private:
// Script Engine Wrapper Interfaces
CComPtr<IActiveScript> m_pEngine;
CComPtr<IActiveScriptParse> m_pEngineParse;
};


//Call function part



::CoInitialize(NULL);

BasicScriptHost* host=NULL;

host->AddScriptFile("C:\Users\123.js");
host->Init();

CComPtr<IDispatch> pJs;
host->GetScriptDispatch(&pJs);
CComVariant var1(10);
CComVariant var2(20);
CComVariant ret;
pJs.Invoke2((LPCOLESTR)"add", &var1, &var2, &ret);
host->Close();
::CoUninitialize();


I think this may be because m_pEngine is invalid, but I don't know how to initialize m_pEngine.







javascript c++ mfc






share|improve this question









New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 19 hours ago









Thelouras

3651314




3651314






New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 22 hours ago









Bathy

91




91




New contributor




Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Bathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
    – tunglt
    20 hours ago












  • @tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
    – Bathy
    6 hours ago
















  • 2




    host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
    – tunglt
    20 hours ago












  • @tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
    – Bathy
    6 hours ago










2




2




host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
– tunglt
20 hours ago






host = NULL so the program crashed when calling host->AddScriptFile(), host must be initialized before it can be used. An error of typing?
– tunglt
20 hours ago














@tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
– Bathy
6 hours ago






@tunglt No,When I call host->Init(); the program runs to hr = ::CoCreateInstance(clsJS,NULL, CLSCTX_INPROC_SERVER, IID_IActiveScript, (void**)&m_pEngine); Crash
– Bathy
6 hours ago



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Bathy is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942662%2fhow-to-fix-cocreateinstance-read-access-violation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Bathy is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Bathy is a new contributor. Be nice, and check out our Code of Conduct.













Bathy is a new contributor. Be nice, and check out our Code of Conduct.












Bathy is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53942662%2fhow-to-fix-cocreateinstance-read-access-violation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas