trouble passing function pointer

P

peter

I can't get this code to link properly. I got two error during link:

error LNK2028: unresolved token (0A00000C) "extern "C" int __stdcall
EnumFontFamiliesExW(struct HDC__ *,struct tagLOGFONTW *,int
(__stdcall*)(struct tagLOGFONTW const *,struct tagTEXTMETRICW const
*,unsigned long,long),long,unsigned long)"
(?EnumFontFamiliesExW@@$$J220YGHPAUHDC__@@PAUtagLOGFONTW@@P6GHPBU2@PBUtagTEXTMETRICW@@KJ@ZJK@Z)
referenced in function "int __clrcall main(cli::array<class System::String ^
^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
error LNK2019: unresolved external symbol "extern "C" int __stdcall
EnumFontFamiliesExW(struct HDC__ *,struct tagLOGFONTW *,int
(__stdcall*)(struct tagLOGFONTW const *,struct tagTEXTMETRICW const
*,unsigned long,long),long,unsigned long)"
(?EnumFontFamiliesExW@@$$J220YGHPAUHDC__@@PAUtagLOGFONTW@@P6GHPBU2@PBUtagTEXTMETRICW@@KJ@ZJK@Z)
referenced in function "int __clrcall main(cli::array<class System::String ^
^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)


//----------- start of code ---------------
#define UNICODE 1
#include "stdafx.h"
#include <windows.h>

int CALLBACK FontNameProc(
ENUMLOGFONTEX *lpelfe,
NEWTEXTMETRICEX *lpntme,
int FontType,
LPARAM lParam
) { return 0; }

int main(array<System::String ^> ^args)
{
LOGFONT logfont;
HDC hdc;
// ignore uninitialized variables warnings for now
EnumFontFamiliesEx(hdc, &logfont, (FONTENUMPROC) FontNameProc, 0, 0);
}
//------------ end of code --------------

The environment is visual C++ express and the IDE, and sdk just downloaded
from microsoft. I also changed a compile-time flag (to disable pure function
or something because of previous warnings). But I can't find where it is
anymore.

Any ideas?
 
N

nbelyh

peter said:
I can't get this code to link properly. I got two error during link:

error LNK2028: unresolved token

The environment is visual C++ express and the IDE, and sdk just downloaded
from microsoft. I also changed a compile-time flag (to disable pure function
or something because of previous warnings). But I can't find where it is
anymore.

Any ideas?

1. Are you sure you want managed project?
2. If yes, are you sure you have registered SDK directories with VC?
3. If yes, are you sure you have added reference to gdi32.lib to
project linker settings?
(the library where EnumFontFamiliesEx is defined)

Regards, Nikolay
 
P

peter

nbelyh said:
1. Are you sure you want managed project?
2. If yes, are you sure you have registered SDK directories with VC?
3. If yes, are you sure you have added reference to gdi32.lib to
project linker settings?
(the library where EnumFontFamiliesEx is defined)

1) I don't care if it's managed or not. I want the simplest build
environment that works.
2) I followed the instructions in this web site:
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/ Why couldn't
the manual editing process be replaced with a script file?

3) no. if I rename gdi32.lib there is no linker error saying it can't find
gdi32.lib (but doing that to uuid.lib does produce a complaint). So it would
seem the linker is not linking to gdi32.lib. Is there a way to reveal what
lib files the linker is linking in?

Is there a way to set up a C++ build environment that is more fool-proof?
 
G

Guest

1) I don't care if it's managed or not. I want the simplest build
environment that works.

If you do not want to use the .NET framework, you should create a win32
console application. You have a CLR console application, which assumes that
you build for the .NET framework, with all the default project settings that
implies.

If you use a win32 console application, I think the errors should go away if
you followed the instructions for installing the platform SDK.
 
P

peter

Bruno van Dooren said:
If you do not want to use the .NET framework, you should create a win32
console application. You have a CLR console application, which assumes
that
you build for the .NET framework, with all the default project settings
that
implies.

If you use a win32 console application, I think the errors should go away
if
you followed the instructions for installing the platform SDK.

I just figured out I can check "inherit project default..." in the linker
additional dependencies options to make the linkage error go away, this is
in addition to following the platform SDK instructions. Without checking
this option, gdi32.lib doesn't get linked in.

I was just contemplating the win32 console template. Now that you suggested
it, I will defintely do it. Although, I wish there is a win32 + dialog
editor template, like VB. Because I'm trying to write an util with one
simple dialog.

Thank you.
 

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