calling a web service from a dll developed in C++

H

hkhokhar

HI All,


I need to develop a dll in C++ which calls a web service for a smart
device/WM. The reason for using C++ is because, that this dll has to
be invoked from a non-dot-net application from the device.

I need to develop the Dll in such a way that i don't have to install
compact framework on the device.

Any help would be appreciated.

Haroon
 
G

Guest

Then you simply need to make the SOAP calls in native code - there's nothing
magical about it and it's documented rather well. Desktop examples will be
relevent becasue you'll be making the same calls as you would on the
desktop.
 
H

hkhokhar

Then you simply need to make the SOAP calls in native code - there's nothing
magical about it and it's documented rather well. Desktop examples will be
relevent becasue you'll be making the same calls as you would on the
desktop.

Hi Chris,

Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains me
how to make a SOAP call in a unmanaged C++ code.

Thanks in advance,

Haroon
 
H

hkhokhar

Hi Chris,

Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains me
how to make a SOAP call in a unmanaged C++ code.

Thanks in advance,

Haroon

Hi Chris,

I did some research and got some initial code to call the web
service.

CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);

However when I run it, it gives me Class not registered error. I don't
have any clue why this error is coming up.

Any help

Haroon
Any help in this regard.
 
P

Paul G. Tobey [eMVP]

This sort of thing is really beyond what can be effectively supported in a
newsgroup in the short-term. You need to know how COM works, so you can go
off and read one of the many books on that to get a feel for what sort of
things are necessary to instantiate COM objects, call their methods, etc.
As you've found, you need to initialize COM to allow anything to work, but
you need also to have any objects that you want to create registered in the
device registry and implemented in DLLs or EXEs on the device. That's what
the error you've gotten is indicating: the code that you're running there is
trying to do a CoCreateInstance() COM call to make an object instance, but
the ID of that object is not found in the device registry, so the call can't
complete.

Paul T.
 
H

hkhokhar

This sort of thing is really beyond what can be effectively supported in a
newsgroup in the short-term. You need to know how COM works, so you can go
off and read one of the many books on that to get a feel for what sort of
things are necessary to instantiate COM objects, call their methods, etc.
As you've found, you need to initialize COM to allow anything to work, but
you need also to have any objects that you want to create registered in the
device registry and implemented in DLLs or EXEs on the device. That's what
the error you've gotten is indicating: the code that you're running there is
trying to do a CoCreateInstance() COM call to make an object instance, but
the ID of that object is not found in the device registry, so the call can't
complete.

Paul T.


On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
Then you simply need to make the SOAP calls in native code - there's
nothing
magical about it and it's documented rather well. Desktop examples
will be
relevent becasue you'll be making the same calls as you would on the
desktop.
--
Chris Tacke, eMVP
Join the Embedded Developer Communityhttp://community.opennetcf.com

HI All,
I need to develop a dll in C++ which calls a web service for a smart
device/WM. The reason for using C++ is because, that this dll has to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have to install
compact framework on the device.
Any help would be appreciated.
Haroon
Hi Chris,
Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,
Haroon
Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I don't
have any clue why this error is coming up.
Haroon
Any help in this regard.

Hi Paul and Chris,

With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.

The point where i am calling the web service method in the code i.e.

HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.

And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.

I am putting my whole function code below.

Could someone please help me where i am doing something wrong.

Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.

Thanks in advance,
Haroon

extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;

using namespace std;

// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();

// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);

ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);

if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("CoInitializeExError");
}
try
{

// Set Proxy
proxy->SetProxy();

// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return result;
}
else
{

file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("ExceptionError");
}
}
 
P

Paul G. Tobey [eMVP]

As with all COM objects, you need to call Release() once for every reference
to the object (COM objects are all reference counted). The wrapper classes
that you're using there may be doing that for you, but I can't tell without
digging into it. What HRESULT value is actually being returned? FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value indicates
what went wrong.

Paul T.

hkhokhar said:
This sort of thing is really beyond what can be effectively supported in
a
newsgroup in the short-term. You need to know how COM works, so you can
go
off and read one of the many books on that to get a feel for what sort of
things are necessary to instantiate COM objects, call their methods, etc.
As you've found, you need to initialize COM to allow anything to work,
but
you need also to have any objects that you want to create registered in
the
device registry and implemented in DLLs or EXEs on the device. That's
what
the error you've gotten is indicating: the code that you're running there
is
trying to do a CoCreateInstance() COM call to make an object instance,
but
the ID of that object is not found in the device registry, so the call
can't
complete.

Paul T.


On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
Then you simply need to make the SOAP calls in native code - there's
nothing
magical about it and it's documented rather well. Desktop examples
will be
relevent becasue you'll be making the same calls as you would on the
desktop.

Chris Tacke, eMVP
Join the Embedded Developer Communityhttp://community.opennetcf.com
I need to develop a dll in C++ which calls a web service for a
smart
device/WM. The reason for using C++ is because, that this dll has
to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have to
install
compact framework on the device.
Any help would be appreciated.

Hi Chris,
Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,

Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I don't
have any clue why this error is coming up.
Haroon
Any help in this regard.

Hi Paul and Chris,

With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.

The point where i am calling the web service method in the code i.e.

HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.

And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.

I am putting my whole function code below.

Could someone please help me where i am doing something wrong.

Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.

Thanks in advance,
Haroon

extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;

using namespace std;

// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();

// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);

ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);

if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("CoInitializeExError");
}
try
{

// Set Proxy
proxy->SetProxy();

// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return result;
}
else
{

file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("ExceptionError");
}
}
 
H

hkhokhar

As with all COM objects, you need to call Release() once for every reference
to the object (COM objects are all reference counted). The wrapper classes
that you're using there may be doing that for you, but I can't tell without
digging into it. What HRESULT value is actually being returned? FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value indicates
what went wrong.

Paul T.


This sort of thing is really beyond what can be effectively supported in
a
newsgroup in the short-term. You need to know how COM works, so you can
go
off and read one of the many books on that to get a feel for what sort of
things are necessary to instantiate COM objects, call their methods, etc.
As you've found, you need to initialize COM to allow anything to work,
but
you need also to have any objects that you want to create registered in
the
device registry and implemented in DLLs or EXEs on the device. That's
what
the error you've gotten is indicating: the code that you're running there
is
trying to do a CoCreateInstance() COM call to make an object instance,
but
the ID of that object is not found in the device registry, so the call
can't
complete.
Paul T.

On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
Then you simply need to make the SOAP calls in native code - there's
nothing
magical about it and it's documented rather well. Desktop examples
will be
relevent becasue you'll be making the same calls as you would on the
desktop.
--
Chris Tacke, eMVP
Join the Embedded Developer Communityhttp://community.opennetcf.com

HI All,
I need to develop a dll in C++ which calls a web service for a
smart
device/WM. The reason for using C++ is because, that this dll has
to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have to
install
compact framework on the device.
Any help would be appreciated.
Haroon
Hi Chris,
Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,
Haroon
Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I don't
have any clue why this error is coming up.
Any help
Haroon
Any help in this regard.
Hi Paul and Chris,
With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.
The point where i am calling the web service method in the code i.e.
HRESULT hr = proxy-
Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.
And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.
I am putting my whole function code below.
Could someone please help me where i am doing something wrong.
Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.
Thanks in advance,
Haroon
extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;
using namespace std;
// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();
// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);
if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("CoInitializeExError");
}
try
{
// Set Proxy
proxy->SetProxy();
// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return result;
}
else
{
file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("ExceptionError");
}
}

Hi Paul,

I did some more testing and found that HRESULT returns -2147467259
value, even though the web service has been called. I searched it on
the net, but could not find any information on it.

Do you any idea, what this error means,

Regards,
Haroon
 
G

Guest

-2147467259 == 0x80004005, which is a very unhelpful "Unspecified error".


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com


hkhokhar said:
As with all COM objects, you need to call Release() once for every
reference
to the object (COM objects are all reference counted). The wrapper
classes
that you're using there may be doing that for you, but I can't tell
without
digging into it. What HRESULT value is actually being returned?
FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value
indicates
what went wrong.

Paul T.


On Feb 26, 2:33 am, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
This sort of thing is really beyond what can be effectively supported
in
a
newsgroup in the short-term. You need to know how COM works, so you
can
go
off and read one of the many books on that to get a feel for what sort
of
things are necessary to instantiate COM objects, call their methods,
etc.
As you've found, you need to initialize COM to allow anything to work,
but
you need also to have any objects that you want to create registered
in
the
device registry and implemented in DLLs or EXEs on the device. That's
what
the error you've gotten is indicating: the code that you're running
there
is
trying to do a CoCreateInstance() COM call to make an object instance,
but
the ID of that object is not found in the device registry, so the call
can't
complete.

On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com>
wrote:
Then you simply need to make the SOAP calls in native code -
there's
nothing
magical about it and it's documented rather well. Desktop
examples
will be
relevent becasue you'll be making the same calls as you would on
the
desktop.

Chris Tacke, eMVP
Join the Embedded Developer
Communityhttp://community.opennetcf.com
I need to develop a dll in C++ which calls a web service for a
smart
device/WM. The reason for using C++ is because, that this dll
has
to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have to
install
compact framework on the device.
Any help would be appreciated.

Hi Chris,
Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains
me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,

Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I
don't
have any clue why this error is coming up.
Haroon
Any help in this regard.
Hi Paul and Chris,
With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.
The point where i am calling the web service method in the code i.e.
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.
And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.
I am putting my whole function code below.
Could someone please help me where i am doing something wrong.
Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.
Thanks in advance,
Haroon
extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;
using namespace std;
// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();
// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);
if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("CoInitializeExError");
}
try
{
// Set Proxy
proxy->SetProxy();
// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return result;
}
else
{
file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("ExceptionError");
}
}

Hi Paul,

I did some more testing and found that HRESULT returns -2147467259
value, even though the web service has been called. I searched it on
the net, but could not find any information on it.

Do you any idea, what this error means,

Regards,
Haroon
 
P

Paul G. Tobey [eMVP]

Great. Well, do everything you can to make sure that you are properly
releasing any resources that you allocate. There's no reason not to do
that. You might try running against a different Web service running on a
different server, to try to localize the error to your server or to the
device. You can do this with just managed code, which should eliminate ATL
or MFC or whatever you're using there.

Paul T.

-2147467259 == 0x80004005, which is a very unhelpful "Unspecified error".


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com


hkhokhar said:
As with all COM objects, you need to call Release() once for every
reference
to the object (COM objects are all reference counted). The wrapper
classes
that you're using there may be doing that for you, but I can't tell
without
digging into it. What HRESULT value is actually being returned?
FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value
indicates
what went wrong.

Paul T.



On Feb 26, 2:33 am, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
This sort of thing is really beyond what can be effectively supported
in
a
newsgroup in the short-term. You need to know how COM works, so you
can
go
off and read one of the many books on that to get a feel for what
sort of
things are necessary to instantiate COM objects, call their methods,
etc.
As you've found, you need to initialize COM to allow anything to
work,
but
you need also to have any objects that you want to create registered
in
the
device registry and implemented in DLLs or EXEs on the device.
That's
what
the error you've gotten is indicating: the code that you're running
there
is
trying to do a CoCreateInstance() COM call to make an object
instance,
but
the ID of that object is not found in the device registry, so the
call
can't
complete.

Paul T.



On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com>
wrote:

Then you simply need to make the SOAP calls in native code -
there's
nothing
magical about it and it's documented rather well. Desktop
examples
will be
relevent becasue you'll be making the same calls as you would on
the
desktop.

--

Chris Tacke, eMVP
Join the Embedded Developer
Communityhttp://community.opennetcf.com



HI All,

I need to develop a dll in C++ which calls a web service for a
smart
device/WM. The reason for using C++ is because, that this dll
has
to
be invoked from a non-dot-net application from the device.

I need to develop the Dll in such a way that i don't have to
install
compact framework on the device.

Any help would be appreciated.

Haroon

Hi Chris,

Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains
me
how to make a SOAP call in a unmanaged C++ code.

Thanks in advance,

Haroon

Hi Chris,

I did some research and got some initial code to call the web
service.

CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);

However when I run it, it gives me Class not registered error. I
don't
have any clue why this error is coming up.

Any help

Haroon
Any help in this regard.

Hi Paul and Chris,

With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.

The point where i am calling the web service method in the code i.e.

HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.

And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.

I am putting my whole function code below.

Could someone please help me where i am doing something wrong.

Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.

Thanks in advance,
Haroon

extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;

using namespace std;

// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();

// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);

ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);

if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("CoInitializeExError");
}
try
{

// Set Proxy
proxy->SetProxy();

// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);

// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return result;
}
else
{

file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();

// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();

// delete file object
delete file;

// Closes the COM library, unloads the dlls
::CoUninitialize();

return CComBSTR("ExceptionError");
}
}

Hi Paul,

I did some more testing and found that HRESULT returns -2147467259
value, even though the web service has been called. I searched it on
the net, but could not find any information on it.

Do you any idea, what this error means,

Regards,
Haroon
 
H

hkhokhar

Great. Well, do everything you can to make sure that you are properly
releasing any resources that you allocate. There's no reason not to do
that. You might try running against a different Web service running on a
different server, to try to localize the error to your server or to the
device. You can do this with just managed code, which should eliminate ATL
or MFC or whatever you're using there.

Paul T.

"<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote in message

-2147467259 == 0x80004005, which is a very unhelpful "Unspecified error".

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
hkhokhar said:
On Feb 27, 2:37 am, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
As with all COM objects, you need to call Release() once for every
reference
to the object (COM objects are all reference counted). The wrapper
classes
that you're using there may be doing that for you, but I can't tell
without
digging into it. What HRESULT value is actually being returned?
FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value
indicates
what went wrong.
Paul T.

On Feb 26, 2:33 am, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
This sort of thing is really beyond what can be effectively supported
in
a
newsgroup in the short-term. You need to know how COM works, so you
can
go
off and read one of the many books on that to get a feel for what
sort of
things are necessary to instantiate COM objects, call their methods,
etc.
As you've found, you need to initialize COM to allow anything to
work,
but
you need also to have any objects that you want to create registered
in
the
device registry and implemented in DLLs or EXEs on the device.
That's
what
the error you've gotten is indicating: the code that you're running
there
is
trying to do a CoCreateInstance() COM call to make an object
instance,
but
the ID of that object is not found in the device registry, so the
call
can't
complete.
Paul T.

On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com>
wrote:
Then you simply need to make the SOAP calls in native code -
there's
nothing
magical about it and it's documented rather well. Desktop
examples
will be
relevent becasue you'll be making the same calls as you would on
the
desktop.
--
Chris Tacke, eMVP
Join the Embedded Developer
Communityhttp://community.opennetcf.com

HI All,
I need to develop a dll in C++ which calls a web service for a
smart
device/WM. The reason for using C++ is because, that this dll
has
to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have to
install
compact framework on the device.
Any help would be appreciated.
Haroon
Hi Chris,
Unfortunately I have not worked that much in C++. Could you please
forward me any link, that would help me get started that explains
me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,
Haroon
Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I
don't
have any clue why this error is coming up.
Any help
Haroon
Any help in this regard.
Hi Paul and Chris,
With little bit of effort, i have managed to run the above code as a
dll which calls a web service.
The dll returns the result of the web service called by a non dot net
application.
Everything seems to be working fine now, but with one very strange
event.
The point where i am calling the web service method in the code i.e.
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
Sometimes while calling this method, the hr variable returns FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells me
that the method has been called successfully even the above code
returned a failure.
And secondly this happens randomly. At one point it happens after 100
calls to the web service method and in second case, it happens in the
first attempt.
I am putting my whole function code below.
Could someone please help me where i am doing something wrong.
Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.
Thanks in advance,
Haroon
extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;
using namespace std;
// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();
// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);
if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("CoInitializeExError");
}
try
{
// Set Proxy
proxy->SetProxy();
// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return result;
}
else
{
file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("ExceptionError");
}
}
Hi Paul,
I did some more testing and found that HRESULT returns -2147467259
value, even though the web service has been called. I searched it on
the net, but could not find any information on it.
Do you any idea, what this error means,
Regards,
Haroon

Hi Paul and Chris,

I refined the code a bit and now the dll only takes only 11k in the
memory and I kept on running the application for full day with 10
seconds interval in each transaction. The problem still remains.
Randomly it throws this error. For some transactions, the web service
is not been called when the error comes in, but for the same error at
some other time, the transaction was been logged at the web service
side.
Totally strange behavior.

I try to make the same app in C#. Maybe ill might see some different
behavior there.

Regards,
Haroon
 
P

Paul G. Tobey [eMVP]

I can't think of anything else to do other than capture the network packets
when a problem happens. Maybe there's someone, a router, a wireless access
point, etc. in the middle of the conversation and it's deciding that you
shouldn't get what you need.

Paul T.

hkhokhar said:
Great. Well, do everything you can to make sure that you are properly
releasing any resources that you allocate. There's no reason not to do
that. You might try running against a different Web service running on a
different server, to try to localize the error to your server or to the
device. You can do this with just managed code, which should eliminate
ATL
or MFC or whatever you're using there.

Paul T.

"<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote in message

-2147467259 == 0x80004005, which is a very unhelpful "Unspecified
error".

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com
On Feb 27, 2:37 am, "Paul G. Tobey [eMVP]" <p space tobey no spam AT
no instrument no spam DOT com> wrote:
As with all COM objects, you need to call Release() once for every
reference
to the object (COM objects are all reference counted). The wrapper
classes
that you're using there may be doing that for you, but I can't tell
without
digging into it. What HRESULT value is actually being returned?
FAILED()
and SUCCEEDED() just check for non-zero and zero; the actual value
indicates
what went wrong.
news:dab5ba52-4940-4a9e-9a52-1d6f3f07b82c@e60g2000hsh.googlegroups.com...

On Feb 26, 2:33 am, "Paul G. Tobey [eMVP]" <p space tobey no spam
AT
no instrument no spam DOT com> wrote:
This sort of thing is really beyond what can be effectively
supported
in
a
newsgroup in the short-term. You need to know how COM works, so
you
can
go
off and read one of the many books on that to get a feel for what
sort of
things are necessary to instantiate COM objects, call their
methods,
etc.
As you've found, you need to initialize COM to allow anything to
work,
but
you need also to have any objects that you want to create
registered
in
the
device registry and implemented in DLLs or EXEs on the device.
That's
what
the error you've gotten is indicating: the code that you're
running
there
is
trying to do a CoCreateInstance() COM call to make an object
instance,
but
the ID of that object is not found in the device registry, so the
call
can't
complete.

On Feb 25, 2:18 pm, "<ctacke/>" <ctacke[at]opennetcf[dot]com>
wrote:
Then you simply need to make the SOAP calls in native code -
there's
nothing
magical about it and it's documented rather well. Desktop
examples
will be
relevent becasue you'll be making the same calls as you would
on
the
desktop.

Chris Tacke, eMVP
Join the Embedded Developer
Communityhttp://community.opennetcf.com
I need to develop a dll in C++ which calls a web service
for a
smart
device/WM. The reason for using C++ is because, that this
dll
has
to
be invoked from a non-dot-net application from the device.
I need to develop the Dll in such a way that i don't have
to
install
compact framework on the device.
Any help would be appreciated.

Hi Chris,
Unfortunately I have not worked that much in C++. Could you
please
forward me any link, that would help me get started that
explains
me
how to make a SOAP call in a unmanaged C++ code.
Thanks in advance,

Hi Chris,
I did some research and got some initial code to call the web
service.
CoInitializeEx(NULL, COINIT_MULTITHREADED);
BSTR result = NULL;
StockQuote::CStockQuoteT<CSoapSocketClientT<>> * ws = new
StockQuote::CStockQuoteT<CSoapSocketClientT<>>();
ws->SetProxy();
HRESULT hr = ws->GetQuote(CComBSTR("SY"),&result);
However when I run it, it gives me Class not registered error. I
don't
have any clue why this error is coming up.
Haroon
Any help in this regard.
Hi Paul and Chris,
With little bit of effort, i have managed to run the above code as
a
dll which calls a web service.
The dll returns the result of the web service called by a non dot
net
application.
Everything seems to be working fine now, but with one very strange
event.
The point where i am calling the web service method in the code
i.e.
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
Sometimes while calling this method, the hr variable returns
FAILURE.
I assum that the web service method has not been called when this
happens.
I am also maintaining the logs at the web service side, which tells
me
that the method has been called successfully even the above code
returned a failure.
And secondly this happens randomly. At one point it happens after
100
calls to the web service method and in second case, it happens in
the
first attempt.
I am putting my whole function code below.
Could someone please help me where i am doing something wrong.
Secondly i am quite new to C++, in this code, is there any memory
leak, which might be shewing up the memory after every dll access.
Thanks in advance,
Haroon
extern "C" BSTR WINAPI processCC(BSTR merchantId,BSTR cc,BSTR
expiryDate,BSTR amount)
{
BSTR result = NULL;
using namespace std;
// Creating Web Service the proxy
Service::CServiceT<CSoapSocketClientT<>> * proxy = new
Service::CServiceT<CSoapSocketClientT<>>();
// If not initialized return NULL
HRESULT h = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
ofstream file;
SYSTEMTIME st;
GetLocalTime(&st);
if(FAILED(h))
{
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("CoInitializeExError");
}
try
{
// Set Proxy
proxy->SetProxy();
// Call the web service. The result is saved in result variable
HRESULT hr = proxy-
ProcessRequest(merchantId,cc,expiryDate,amount,&result);
// If not succeeded return NULL;
if (SUCCEEDED(hr))
{
file.open("payments.log",ios::app);
file << st.wHour << ":" << st.wMinute << ":" << st.wSecond <<
"\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return result;
}
else
{
file.open("payments.log",ios::app);
file << "Failure: " << st.wHour << ":" << st.wMinute << ":" <<
st.wSecond << "\n";
file.close();
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("WebServiceCallFailed");
}
}
catch(char *error)
{
//MessageBox(0,CComBSTR("Exception Error"),CComBSTR("Exception
Error"),0);
// Uninitialize proxy object.
proxy->Uninitialize();
proxy->Cleanup();
// delete file object
delete file;
// Closes the COM library, unloads the dlls
::CoUninitialize();
return CComBSTR("ExceptionError");
}
}
I did some more testing and found that HRESULT returns -2147467259
value, even though the web service has been called. I searched it on
the net, but could not find any information on it.
Do you any idea, what this error means,
Regards,
Haroon

Hi Paul and Chris,

I refined the code a bit and now the dll only takes only 11k in the
memory and I kept on running the application for full day with 10
seconds interval in each transaction. The problem still remains.
Randomly it throws this error. For some transactions, the web service
is not been called when the error comes in, but for the same error at
some other time, the transaction was been logged at the web service
side.
Totally strange behavior.

I try to make the same app in C#. Maybe ill might see some different
behavior there.

Regards,
Haroon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top