From: ks on
Hi all,

I'm trying to learn C++/Win32 to facilitate my C# Interop woes. I have
a beginning understanding of it but am having troubles with my Visual
Studio 2005 project when trying to make a call to a function. I have a
very short code example below which gives me the following build
warnings/errors.
I tried googling for an answer to this but didn't have any luck. I
created my project as follows:

New->Project->Win32->Win32 Console Application

and checked ATL.


I really have no idea why I'm not able to link to functions in the
setupapi.dll or how to fix this. Help would be wonderfully appreciated.


Error 2 error LNK2019: unresolved external symbol
__imp__SetupDiClassGuidsFromNameW(a)16 referenced in function
_wmain SetupApiConsole.obj

Error 3 fatal error LNK1120: 1 unresolved externals C:\Documents and
Settings\Michael\My Documents\Visual Studio
2005\Projects\SetupApiConsole\Debug\SetupApiConsole.exe




#include "stdafx.h"
#include "setupapi.h"

int _tmain(int argc, _TCHAR* argv[])
{
PCWSTR ClassName = TEXT("MEDIA");
LPGUID ClassGuidList;
DWORD ClassGuidListSize = 0;
DWORD RequiredSize;

SetupDiClassGuidsFromName(ClassName, ClassGuidList, ClassGuidListSize,
&RequiredSize);

return 0;
}



-ks

From: David Lowndes on
>I really have no idea why I'm not able to link to functions in the
>setupapi.dll or how to fix this.

You need to add (I presume it's called) setupapi.lib to the list of
libraries that you link to - in your project's Link settings.

Dave
From: ks on

David Lowndes wrote:
> >I really have no idea why I'm not able to link to functions in the
> >setupapi.dll or how to fix this.
>
> You need to add (I presume it's called) setupapi.lib to the list of
> libraries that you link to - in your project's Link settings.
>
> Dave


Thanks for the advice.. I'm not sure how to do that properly but have
been trying :)

Thanks
-ks

From: ks on

ks wrote:
> David Lowndes wrote:
> > >I really have no idea why I'm not able to link to functions in the
> > >setupapi.dll or how to fix this.
> >
> > You need to add (I presume it's called) setupapi.lib to the list of
> > libraries that you link to - in your project's Link settings.
> >
> > Dave
>
>
> Thanks for the advice.. I'm not sure how to do that properly but have
> been trying :)
>
> Thanks
> -ks

I don't know if this is the recommend method/way of doing this, but I
just added the file SetupAPI.Lib to the project and now it
compiles/builds/runs.

Thanks,
-ks

From: [Jongware] on
"ks" <karan.shashi(a)gmail.com> wrote in message
news:1160123979.843590.151770(a)i42g2000cwa.googlegroups.com...
>
> ks wrote:
>> David Lowndes wrote:
>> > >I really have no idea why I'm not able to link to functions in the
>> > >setupapi.dll or how to fix this.
>> >
>> > You need to add (I presume it's called) setupapi.lib to the list of
>> > libraries that you link to - in your project's Link settings.
>> >
>> > Dave
>>
>>
>> Thanks for the advice.. I'm not sure how to do that properly but have
>> been trying :)
>>
>> Thanks
>> -ks
>
> I don't know if this is the recommend method/way of doing this, but I
> just added the file SetupAPI.Lib to the project and now it
> compiles/builds/runs.

The lib file contains the (coded) entry points to the DLL functions. The
compiler never sees the DLL functions, and doesn't even need to (!), but it
needs to insert code in your program where to find them. As there are lots
and lots of libraries, only the most important ones are added to your VC
project per default. It is not quite "recommended" as such, but by design.

[Jongware] -- like it or not, always happy to break in with some bg info