error C2065: 'hdll' : undeclared identifier

泡芙女孩儿 2012-10-22 11:19:37
刚刚编写了一个动态链接库的实例,却出现这样的错误,求高手指教。
#include "stdafx.h"
#include "a.h"
#include "aDlg.h"
__________________________________________________
___________________________________________________
void CADlg::OnButton1()
{
// TODO: Add your control notification handler code here
hdll=loadLibrary("text.dll");
if(hdll)
{
typedef void(*PROCTYPE);
PROCTYPE myprint=(PROCTYPE)GetProcAddress(hdll,"print");//得到函数地址
(*myprint)();
}
FreeLibrary(hdll);//释放库
}
_______________________________________________________________
_________________________
--------------------Configuration: a - Win32 Debug--------------------
Compiling...
aDlg.cpp
C:\Documents and Settings\Administrator\桌面\text\a\aDlg.cpp(177) : error C2065: 'hdll' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\text\a\aDlg.cpp(177) : error C2065: 'loadLibrary' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\text\a\aDlg.cpp(182) : error C2100: illegal indirection
C:\Documents and Settings\Administrator\桌面\text\a\aDlg.cpp(182) : error C2064: term does not evaluate to a function
Error executing cl.exe.

aDlg.obj - 4 error(s), 0 warning(s)



若是添加链接库的头文件#include "text.h"会出现这样的错误,求教哪位大侠能帮忙分析一下,给出正解。
#include "stdafx.h"
#include "a.h"
#include "aDlg.h"
#include "text.h"
———————————————————————————————
______________________________________________
--------------------Configuration: a - Win32 Debug--------------------
Compiling...
aDlg.cpp
C:\Documents and Settings\Administrator\桌面\text\a\aDlg.cpp(7) : fatal error C1083: Cannot open include file: 'text.h': No such file or directory
Error executing cl.exe.

a.exe - 1 error(s), 0 warning(s)
...全文
143 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
图灵狗 2012-10-22
  • 打赏
  • 举报
回复
1、hdll没有定义就直接使用了;
2、loadLibrary前面的l需要大写;
3、需要#include<windows.h>。
自己写的小小小程序,能实现简单的通信 // Client.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #include #include "Thread.h" #pragma comment(lib,"ws2_32.lib") #define PORT 4567 #define BUFFERMAX 256 CRITICAL_SECTION cs; int main() { WSADATA wsaData; WORD sockVersion = MAKEWORD(2, 2); if (WSAStartup(sockVersion, &wsaData) != 0) { std::cout << "Initlization failed" << std::endl; system("pause"); return 0; } SOCKET clientSocket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (clientSocket == INVALID_SOCKET) { std::cout << "Failed socket!"<< std::endl; system("pause"); return 0; } sockaddr_in serverSockAddr; serverSockAddr.sin_family = AF_INET; serverSockAddr.sin_port = htons(PORT); InetPton(AF_INET,_T("127.0.0.1"),&(serverSockAddr.sin_addr.S_un.S_addr)); if (connect(clientSocket, (sockaddr*)&serverSockAddr, sizeof(sockaddr))) { std::cout << "Connect failed!" << std::endl; } InitializeCriticalSection(&cs); connection(clientSocket, (sockaddr*)&serverSockAddr); char * sendData = "你好,TCP服务端,我是客户端!\n"; send(clientSocket, sendData, strlen(sendData), 0); //volatile int connect_flag = 0; sock_Attribute sock_R = { clientSocket,0,&serverSockAddr}; sock_Attribute sock_S = { clientSocket,0,&serverSockAddr}; HANDLE hdll = CreateThread(NULL, 0, recv_Thread, &sock_R, 0, 0); if (hdll == nullptr) { std::cout << "创建线程失败" << std::endl; } send_Thread(&sock_S); system("pause"); DeleteCriticalSection(&cs); closesocket(clientSocket); WSACleanup(); return 0; } DWORD WSAAPI recv_Thread(LPVOID P) //不加 WSAAPI 关键字会报错,可能跟调用方式有关 { char recvBuffer[BUFFERMAX] = "\0"; int nRecv; int size = sizeof(recvBuffer); sock_Attribute* pSock = (sock_Attribute*)P; for (;;) { nRecv = recv(pSock->s, recvBuffer, size, pSock->flags); if (nRecv == SOCKET_ERROR||nRecv ==0) { connection(pSock->s, (sockaddr*)(pSock->serverAddr)); //break; } if(nRecv>0) { if (recvBuffer != '\0') // '\0' 即 NULL { std::cout << "Client : " << recvBuffer << std::endl; //*recvBuffer = NULL; memset(recvBuffer, 0x00, size); /* 字符串用字符串函数操作, 数组用指针操作,*/ } } } return 0; } DWORD WSAAPI send_Thread(LPVOID P) { sock_Attribute* pSock = (sock_Attribute*)P; char sendBuffer[BUFFERMAX] = "\0"; int size = sizeof(sendBuffer); for (;;) { std::cin.getline(sendBuffer, size); switch (send(pSock->s, sendBuffer,size, pSock->flags)) { case SOCKET_ERROR: { connection(pSock->s, (sockaddr*)(pSock->serverAddr)); break; } default: break; } } return 0; }

64,650

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧