Problem in Calling native code from managed c++ dll.

H

Haroon_Saeed

Hey,

I wrote a managed c++ class library in viusal studio 2005. This managed
c++ dll calls native C++ methods of an SDK. When I referenced this
managed c++ library in a console applciation written in C# for testing
every thing worked fine. Now I need to call the managed c++ class
library through web service written in C#. When I call managed c++
methods from web service the code crashes on the line from where the
native code starts( mean native class's objects are instatiated). Can
any one help me in this regard. It's kinda hurry. Thanks.
 
J

Jochen Kalmbach [MVP]

Hi Haroon!
I wrote a managed c++ class library in viusal studio 2005. This managed
c++ dll calls native C++ methods of an SDK. When I referenced this
managed c++ library in a console applciation written in C# for testing
every thing worked fine. Now I need to call the managed c++ class
library through web service written in C#. When I call managed c++
methods from web service the code crashes on the line from where the
native code starts( mean native class's objects are instatiated). Can
any one help me in this regard. It's kinda hurry. Thanks.

What is the exact expection message?
It might have to do with the "security" settings; which might not allow
to call unmanaged code.

Greetings
Jochen
 
A

adebaene

Haroon_Saeed said:
Hey,

I wrote a managed c++ class library in viusal studio 2005. This managed
c++ dll calls native C++ methods of an SDK. When I referenced this
managed c++ library in a console applciation written in C# for testing
every thing worked fine. Now I need to call the managed c++ class
library through web service written in C#. When I call managed c++
methods from web service the code crashes on the line from where the
native code starts( mean native class's objects are instatiated). Can
any one help me in this regard. It's kinda hurry. Thanks.

Generally speaking, web services run under restricted accouts and with
restricted privilieges. I'll bet you do not have the UnmanagedCode
SecurityPermission flag set when you are running under the web service.

Either mark your managed C++ with the SuppressUnmanagedCodeSecurity
attribute (but do this only if you are truly aware of the
implications!), or have your web service run under another account with
the correct permissions. In any case, you must be aware that this is a
potential security weakness to let a web service call on unmanaged,
unprotected, code.

Arnaud
MVP - VC
 

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