I am having a piece of visual C++ code (firebreath) that retrieves data from a visual C# application. The communication works fine for negative cases(returns value without out parameter) but in positive case(returns value with out parameter) the following error is shown.
Error: Error calling method on NPObject!
I guess the problem is in the out parameter of Visual C# application. Can anyone help me in this?? Kindly use the below code for reference.
ngContent.js: (js to call firebreath function)
function GetDetails(param1, param2) {
try {
return document.getElementById("nGCall").ReturnDetails(param1, param2);
}
catch (e) {
alert("Exception Occured " + e.message);
}
};
nGAPI.cpp: (Firebreath function to call C# application)
FB::VariantList nGAPI::ReturnDetails(std::wstring& param1, std::wstring& param2)
{
try {
InetGuardNPAPI *CSharpInterface = NULL;
//Open interface to C#
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_netGuardIEBHO, NULL, CLSCTX_INPROC_SERVER, IID_InetGuardNPAPI, reinterpret_cast<void**>(&CSharpInterface));
BSTR out1= NULL;
BSTR out2= NULL;
BSTR out3= NULL;
BSTR out4= NULL;
int returns = CSharpInterface->NPGetDetails(param1.c_str(), param2.c_str(), &out1, &out2, &out3, &out4);
if (out1 != NULL && out2 != NULL) {
return FB::variant_list_of(out1)(out2)(out3)(out4);
} else {
return FB::variant_list_of();
}
} catch (...) {
MessageBoxW(NULL, L"Exception occured.", L"NG", NULL);
return FB::variant_list_of();
}
nGHost.cs: (Visual C# application)
public int NPGetDetails(string param1, string param2, out string out1, out string out2, out string out3, out string out4)
{
int retValue = 0;
out1 = null;
out2 = null;
out3 = null;
out4 = null;
bool userIdentified = IdentifyUser(ngDB, out ngdata);
if (!userIdentified)
return retValue;
try {
out1 = ngdata.abc;
out2 = ngdata.def;
out3 = ngdata.ghi;
out4 = ngdata.jkl;
retValue = 1;
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
return retValue;
}
Thanks in advance.
The error you're getting indicates that an exception was thrown. Unfortunately the browsers stopped exposing exceptions when they switched to out of process plugins. I'd recommend attaching a debugger and stepping through to see what is actually happening; alternately, add some logging.