Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unmanaged VC++ from Managed C++

8 views
Skip to first unread message

Ken Johnson

unread,
May 30, 2002, 4:44:45 PM5/30/02
to
I have a v6.0 Win32 static library that is linked to a v6.0 dynamic link
library.
When I look at Depends to find the name of a function located in the static
library,
I can't locate it anywhere. How do I use DllImport in my managed dll to
call a
function from a static library? Also, what about a unmanaged class member?
Anything special using DllImport? Every sample that I have found uses
MessageBox from kernel32.

Thanks.

Ken


David Lowndes

unread,
May 30, 2002, 5:52:14 PM5/30/02
to
>I have a v6.0 Win32 static library that is linked to a v6.0 dynamic link
>library.
>When I look at Depends to find the name of a function located in the static
>library,
>I can't locate it anywhere.

Ken,

That's to be expected. They aren't the same as your exported DLL
functions.

> How do I use DllImport in my managed dll to
>call a
>function from a static library?

You don't need to - just #include the header file that defines your
static library functions, and add that static library's .lib file to
the list of linked libraries for your DLL project.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.

Ken Johnson

unread,
May 31, 2002, 8:34:13 AM5/31/02
to
The function that I am trying to call from the static library opens a
COleDocument.
When I compile and link my managed c++ web service with the call to this
function,
I get the following error immediately in the browser. If I simply comment
out the
call, it works fine. (Other than not doing what I need it to do.)

Parser Error Message: File or assembly name VPDataReader, or one of its
dependencies, was not found.

Source Error:

Line 170: <add assembly="System.Drawing, Version=1.0.3300.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 171: <add assembly="System.EnterpriseServices,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
Line 172: <add assembly="*"/>
Line 173: </assemblies>
Line 174:


Source File:
c:\winnt\microsoft.net\framework\v1.0.3705\Config\machine.config Line:
172

Assembly Load Trace: The following information can be helpful to determine
why the assembly 'VPDataReader' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = VPDataReader
(Partial)
LOG: Appbase = file:///c:/inetpub/wwwroot/VPDataReader
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: VPDataReader
LOG: Attempting download of new URL
file:///C:/WINNT/Microsoft.NET/Framework/v1.0.3705/Temporary ASP.NET
Files/vpdatareader/0b262eeb/20817507/VPDataReader.DLL.
LOG: Attempting download of new URL
file:///C:/WINNT/Microsoft.NET/Framework/v1.0.3705/Temporary ASP.NET
Files/vpdatareader/0b262eeb/20817507/VPDataReader/VPDataReader.DLL.
LOG: Attempting download of new URL
file:///c:/inetpub/wwwroot/VPDataReader/bin/VPDataReader.DLL.
LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).
LOG: Post-policy reference: VPDataReader, Version=1.0.881.11565,
Culture=neutral, PublicKeyToken=null


Any ideas? I do appreciate the help David.

Ken


"David Lowndes" <dav...@mvps.org> wrote in message
news:pi7dfu01u5l28lgbn...@4ax.com...

David Lowndes

unread,
May 31, 2002, 8:39:57 AM5/31/02
to
>The function that I am trying to call from the static library opens a
>COleDocument.
>When I compile and link my managed c++ web service with the call to this
>function,
>I get the following error immediately in the browser.

No idea - sorry :(

Ken Johnson

unread,
May 31, 2002, 9:28:42 AM5/31/02
to
Any other takers?

If I recreate the web service as C# instead of MC++, is there a way to still
link the static C++ lib?

Ken

"David Lowndes" <dav...@mvps.org> wrote in message

news:7lrefu4mbpmgfdkec...@4ax.com...

Tomas Restrepo [MVP]

unread,
May 31, 2002, 1:45:48 PM5/31/02
to
Ken,

> The function that I am trying to call from the static library opens a
> COleDocument.
> When I compile and link my managed c++ web service with the call to this
> function,
> I get the following error immediately in the browser. If I simply comment
> out the
> call, it works fine. (Other than not doing what I need it to do.)
>
> Parser Error Message: File or assembly name VPDataReader, or one of its
> dependencies, was not found.

Is your unmanaged DLL in your service's bin directory, or at least in a
directory referenced in your PATH variable?

--
Tomas Restrepo
tom...@mvps.org


Ronald Laeremans [MSFT]

unread,
May 31, 2002, 1:57:17 PM5/31/02
to
No.

-Ronald-

"Ken Johnson" <kjoh...@vp.com> wrote in message
news:e23m8bKCCHA.2580@tkmsftngp05...

Ken Johnson

unread,
May 31, 2002, 4:06:44 PM5/31/02
to
Yes. They are in the services bin directory.

Ken


"Tomas Restrepo [MVP]" <tom...@mvps.org> wrote in message
news:#65xPrMCCHA.2444@tkmsftngp05...
> Ken,

Sergiy Mesropyan

unread,
May 31, 2002, 4:46:23 PM5/31/02
to
Yes. :)

If I'm correct then that's what is happening:

ASP.NET tries to preload all assemblies from you bin folder (don't ask why)
When it loads your unmanaged dll and tries to treat is as assembly it fails
and throws exception. (to MS: by the way why? isn't suppose just ignore the
file it does not understand). So you have two options:

1. Move you unmanaged DLL to somewhere where it will be accessible through
PATH variable.
2. Add the following to your web.config to prevent ASP.NET assembly
preloading.
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<remove assembly="*"/>
</assemblies>
</compilation>
</system.web>
</configuration>


Let me know if it helps.


"Ken Johnson" <kjoh...@vp.com> wrote in message
news:e23m8bKCCHA.2580@tkmsftngp05...

Bobby Mattappally [MS]

unread,
Jun 3, 2002, 9:26:45 PM6/3/02
to
Try opening VPDataReader.dll using depends and see the dependent dlls
listed.
Make sure you have all the dependent dlls available in the path.
The latest vesion of dependency walker available from:
www.dependencywalker.com

has a profile option which might also be useful.

Hope this helps.
Thank you,
Bobby Mattappally
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Ken Johnson" <kjoh...@vp.com>

0 new messages