function-style conversion to builtin type takes only one argument
来源:互联网 发布:长期股权投资转换知乎 编辑:程序博客网 时间:2024/05/17 01:06
今天同事遇到一个问题:error C2564:‘xxxx’:a function-style conversion to a built-in type can only take one argument
之前没有遇到过,于是到网上查了一下,发现如下文章的error场景与他的十分类似:
http://forums.codeguru.com/showthread.php?327586-C-Newbie-What-have-I-done-wrong
文章中提到的原因是:
typedef 定义的函数指针,是一种类型。我们调用方法要使用该类型的变量。
下面是我的测试:
dll:
头文件:其中DLLEXPORT是定义在stdafx.h中 #define DLLEXPORT
#ifdef DLLEXPORT#define MY_API _declspec(dllexport)#else#define MY_API _declspec(dllimport)#endifextern "C" {MY_API int send(char* thisNumber, int flag);}
源文件
#include "stdafx.h"#include "ErrorTestDll.h"#include <iostream>int send(char* thisNumber, int flag) {printf("hello world! number:%c, flag:%d \n", *thisNumber, flag);return 1;}
调用dll的控制台工程代码:
#include "stdafx.h"#include <Windows.h>typedef int (*mySend)(char* thisNumber, int flag);int _tmain(int argc, _TCHAR* argv[]){HINSTANCE dllHandle = NULL;dllHandle = LoadLibrary("E:\\test\\ErrorTestDll\\Debug\\ErrorTestDll.dll");mySend fp = (mySend)GetProcAddress(dllHandle, "send");mySend fp2;char ch = 'A';//int t = fp(&ch, 1); // 正确的调用形式//int t = fp2(&ch, 1); int t = mySend(&ch, 1); // 文中出错是由于这样的调用。printf("t : %d", t);while(1);return 0;}
编译结果:
error C2564: 'mySend' : a function-style conversion to a built-in type can only take one argument
如测试结果所示:使用函数指针的定义直接当作函数来调用,确实是不行的。
其实导致错误的原因很简单,就是没有正确使用函数指针。
另外,上述测试代码中使用dll的方式,也值得我们参考:
1、它是动态加载dll的,
2、它没有依赖dll的头文件,仅仅是通过GetProcAddress指定的函数名定位到函数的。
3、typedef定义的函数指针,让我们知道dll的本质,我只要知道你的接口(dll)是什么样子的,我就可以调用你。
调用dll的过程非常简洁,我们可以应用到自己的项目中。
0 0
- function-style conversion to builtin type takes only one argument
- How to test only one benchmark function?
- How to fix the python problem 'xxx() takes exactly one argument'
- Incompatible argument to function
- Promise.then fired with only one argument?
- CONVERT function [Data type conversion]
- Syntax error on line 198 httpd.conf: ServerAdmin takes one argument
- [乐意黎]Apache重启后抛order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'
- CMake: include called with wrong number of arguments. include() only takes one file.
- non-numeric second argument to `wordlist' function: '
- non-numeric second argument to `wordlist' function
- non-numeric second argument to `wordlist' function
- " wrong type argument to unary exclamation mark"
- render_template() takes exactly 1 argument
- Data type conversion sheet : C++ to .NET
- Type conversion - unsigned to signed int/char
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- error C2679: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion
- 学长留的DFS题1-1
- jq 移动端禁止滑屏 消除禁止滑屏
- “杀猪车”,哪里逃?!
- 第8周项目4-字符串加密
- 登录vpn提示没有安装java
- function-style conversion to builtin type takes only one argument
- QT读取剪贴板信息和拖动文件到程序以(拖动音乐播放为列)
- 随笔
- 6 OC基础06
- python 学习--定制类
- GCD的一些简单使用
- react-native打离线bundle包
- oracle卸载重装,碰到问题,“[INS-07009] 无法加载 BeanStore”
- 求s = a+aa+aaa+aaaa+a......a的值,其中a是一个数字