转换函数指针:任何人都可以更正此MS知识库示例请参阅? [英] Casting Function pointers : Can anyone correct this MS Knowledge base Example pls ?

查看:60
本文介绍了转换函数指针:任何人都可以更正此MS知识库示例请参阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对c ++知之甚少,但我想在

示例。 com / kb / q246772 /target =_ blank> http://support.microsoft.com/kb/q246772/


HOWTO:在Windows中检索并设置默认打印机

我包含了#include< Windows.h>在开始时,以下是

错误:


BOOL DPGetDefaultPrinter(LPTSTR pPrinterName,LPDWORD pdwBufferSize)

{

....

PROC fnGetDefaultPrinter = NULL;

....

//此行适用:

fnSetDefaultPrinter = GetProcAddress(hWinSpool,SETDEFAULTPRINTER);

....

bFlag = fnGetDefaultPrinter(pPrinterName,pdwBufferSize);

//但是这个给了

// GetDfltPrt.cpp(100):错误C2197:''int(__ stdcall *)(void)'':太多

很多实际参数

....

bFlag = fnSetDefaultPrinter(pPrinterName);

//这个也是一样的。


这可能应该是铸造的,因为参数的数量是不同的。

也欢迎对此代码的评论。是否有更好的方法可以在所有Windows平台上获得默认打印机?

非常感谢提前。

Dirk。

I have only small knowledge of c++, but I would like to compile the
example in
http://support.microsoft.com/kb/q246772/
HOWTO: Retrieve and Set the Default Printer in Windows
I included "#include <Windows.h>" at the start, and the following goes
wrong :

BOOL DPGetDefaultPrinter(LPTSTR pPrinterName, LPDWORD pdwBufferSize)
{
....
PROC fnGetDefaultPrinter = NULL;
....
// This line works :
fnSetDefaultPrinter = GetProcAddress(hWinSpool, SETDEFAULTPRINTER);
....
bFlag = fnGetDefaultPrinter(pPrinterName, pdwBufferSize);
// but this one gives
// GetDfltPrt.cpp(100) : error C2197: ''int (__stdcall *)(void)'' : too
many actual parameters
....
bFlag = fnSetDefaultPrinter(pPrinterName);
// and this gives the same.

This should probably be casted, because the number of parameters is
different.
Comments on this code are also welcome. Are there better ways to get
the default printer on all windows platforms ?
Many thanks in advance.
Dirk.

推荐答案

Dirk Vanhaute发布:
Dirk Vanhaute posted:
我对c ++知之甚少,但我想编译

中的示例 http://support.microsoft.com/kb/ q246772 /
HOWTO:在Windows中检索和设置默认打印机
我包含了#include< Windows.h>在开始时,以下是错误的:

BOOL DPGetDefaultPrinter(LPTSTR pPrinterName,LPDWORD pdwBufferSize)
{
...
PROC fnGetDefaultPrinter = NULL;
...
//此行有效:
fnSetDefaultPrinter = GetProcAddress(hWinSpool,SETDEFAULTPRINTER);
...
bFlag = fnGetDefaultPrinter(pPrinterName,pdwBufferSize );
//但是这个给了
// GetDfltPrt.cpp(100):错误C2197:''int(__ stdcall *)(void)'':太多
许多实际参数
...
bFlag = fnSetDefaultPrinter(pPrinterName);
I have only small knowledge of c++, but I would like to compile the
example in
http://support.microsoft.com/kb/q246772/
HOWTO: Retrieve and Set the Default Printer in Windows
I included "#include <Windows.h>" at the start, and the following goes
wrong :

BOOL DPGetDefaultPrinter(LPTSTR pPrinterName, LPDWORD pdwBufferSize)
{
...
PROC fnGetDefaultPrinter = NULL;
...
// This line works :
fnSetDefaultPrinter = GetProcAddress(hWinSpool, SETDEFAULTPRINTER);
...
bFlag = fnGetDefaultPrinter(pPrinterName, pdwBufferSize);
// but this one gives
// GetDfltPrt.cpp(100) : error C2197: ''int (__stdcall *)(void)'' : too
many actual parameters
...
bFlag = fnSetDefaultPrinter(pPrinterName);



如果你的功能如下:


int Blah(char,int,bool);

然后定义一个指向这种*类型*函数的指针,你这样做:


int( * p_Blah)(char,int,bool)= Blah;

您的代码中发生的事情是这些类型不匹配。这类似于

执行以下操作:


void Blah(int);


char( * p_Blah)(char,bool,float)= Blah;

你需要做的就是改变指针的类型!

-JKop


If you have a function that looks like so:

int Blah(char, int, bool);
then to define a pointer to such a *type* of function, you do:

int (*p_Blah)(char, int, bool) = Blah;
What''s happening in your code is that the types don''t match. It''s akin to
doing the following:

void Blah(int);

char (*p_Blah)(char,bool,float) = Blah;
What you need to do is change the type of your pointer!
-JKop


>
这应该是可以投入的,因为参数的数量是不同的。


似乎合理。

也欢迎对此代码发表评论。


这是通常的一堆狗屎。

有没有更好的方法来获得所有Windows平台上的默认打印机?


不知道,请问Windows编程组。您的问题不在主题上,因为两个不同的原因,首先是代码是C而不是C ++,其次是Windows

编程不是C ++语言组中的主题。试试

news:comp.os.ms-windows.programmer.win32。

非常感谢提前。
Dirk。
This should probably be casted, because the number of parameters is
different.
Seems reasonable.
Comments on this code are also welcome.
It''s the usual pile of shit.
Are there better ways to get
the default printer on all windows platforms ?
No idea, ask on a Windows programming group. Your question is off topic for
two different reasons, firstly the code is C not C++, secondly Windows
programming is not on topic in a C++ language group. Try
news:comp.os.ms-windows.programmer.win32.
Many thanks in advance.
Dirk.




john



john




" John Harrison" <乔************* @ hotmail.com>在消息中写道

news:2t ************* @ uni-berlin.de ...

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2t*************@uni-berlin.de...

这应该是可以投入的,因为参数的数量是不同的。

This should probably be casted, because the number of parameters is
different.



似乎是合理的。



Seems reasonable.

也欢迎对这段代码的评论。
Comments on this code are also welcome.



这是一堆乱糟糟的东西。



It''s the usual pile of shit.




个人厌恶Windows编程在这里表达?或C风格的API

通常会调用?


您可能不喜欢Windows,但我们很多人都必须编写运行的C ++代码该平台上的
。由于API是在C中,我们在C ++代码中坚持使用C风格的
接口。



Personal aversion to Windows programming expressed here? Or C-style API
calls in general?

You may not like Windows, but a lot of us have to write C++ code that runs
on that platform. And since the API is in C, we''re stuck with C-style
interfaces in our C++ code.

有没有更好的方法来获得所有Windows平台上的默认打印机?
Are there better ways to get
the default printer on all windows platforms ?



不知道,请问Windows编程组。你的问题不是主题
因为两个不同的原因,首先是代码是C而不是C ++,其次是Windows编程不是C ++语言组的主题。试试
news:comp.os.ms-windows.programmer.win32。



No idea, ask on a Windows programming group. Your question is off topic
for
two different reasons, firstly the code is C not C++, secondly Windows
programming is not on topic in a C++ language group. Try
news:comp.os.ms-windows.programmer.win32.




它是有效的C ++代码。当然,它正在调用一个C API函数,但是如果

程序是一个C ++程序,那么问题可能是/ b $ b被认为是C ++是合理的问题。


问题显然是PROC的定义,但没有显示。

OP需要定义函数指针以匹配函数声明,

,这显然不是。只需使用PROC即可。不是答案。 OP

需要获得函数的实际声明,并定义一个与该声明匹配的指针




但是,你是对的,因为我们没有(而且不是$ b)这些信息是他可能需要去Windows新闻组的东西。 $ b特别关心)这里的信息。


-Howard



It''s valid C++ code. Sure, it''s calling a C API function, but if the
program is a C++ program, it''s reasonable that the question could be
considered a C++ question.

The problem is apparently the definition of "PROC", which isn''t shown. The
OP needs to define the function pointer to match the function declaration,
which it obviously doesn''t. Simply using "PROC" is not the answer. The OP
needs to get the actual declaration of the function, and define a pointer
that matches that declaration.

However, you''re right that THAT information is something the he probably
needs to go to a Windows newsgroup for, since we don''t have (and don''t
particularly care about) that info here.

-Howard


这篇关于转换函数指针:任何人都可以更正此MS知识库示例请参阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆