There are two outright errors in the code I posted (stupidly I didn't actually copy/paste it from what I ran). I left "resource->dc" which should have been changed to "hdc". And I spelled enumFamCallBack once like that and the other time like enumFamCallback (lowercase b). They need to be the same.
All the other errors are about the _T() and _txxx function stuff, which is about allowing the character set to be ANSI or UNICODE, but you seem to be using ANSI.
First try including <tchar.h>.
If that doesn't work, then try removing all the TCHAR, _T and _txxx function stuff like this (I fixed the two outright errors, too) :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wingdi.h>
#include <winspool.h>
#define MAX_FONTS 1000
typedef struct {
LONG weight;
BYTE italic;
BYTE underline;
BYTE strikeOut;
char faceName[LF_FACESIZE];
} FontParams;
typedef struct {
FontParams fonts[MAX_FONTS];
int count;
} Fonts;
int CALLBACK
enumFamCallback(const LOGFONT *font, const NEWTEXTMETRIC *tm,
DWORD type, LPARAM lParam) {
Fonts *f = (Fonts*)lParam;
if (f->count >= MAX_FONTS)
return 0; // list is full; stop enumeration
FontParams *fp = &f->fonts[f->count++];
fp->weight = font->lfWeight;
fp->italic = font->lfItalic;
fp->underline = font->lfUnderline;
fp->strikeOut = font->lfStrikeOut;
strcpy_s(fp->faceName, LF_FACESIZE, font->lfFaceName);
// or maybe just: strcpy(fp->faceName, font->lfFaceName);
return 1;
}
void listFonts(Fonts *fonts) {
fonts->count = 0; // must zero the count
HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
EnumFontFamilies(hdc,
(LPCSTR)NULL,
(FONTENUMPROC)enumFamCallback,
(LPARAM)fonts);
DeleteDC(hdc);
}
int main() {
Fonts fonts;
listFonts(&fonts);
printf("Font families found: %d\n", fonts.count);
for (int i = 0; i < fonts.count; i++)
printf("%s\n", fonts.list[i].faceName);
return 0;
}