Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 链接器错误,未定义引用_Winapi - Fatal编程技术网

Winapi 链接器错误,未定义引用

Winapi 链接器错误,未定义引用,winapi,Winapi,我是个十足的初学者。这是我的第一个C++代码。从DEV C++中的默认项目、YouTube教程和一些直觉,我想出了下面的简单代码。我知道答案很简单。我似乎无法将其他帖子的答案粘贴到一起,以解决我的问题。非常感谢您提供的任何帮助 我得到“未定义对CreateProcessWithLogonW的引用”错误 #包括 /*声明Windows过程*/ LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM); HWND文本字段; /*将类名设置为全局变量*/ char szClassN

我是个十足的初学者。这是我的第一个C++代码。从DEV C++中的默认项目、YouTube教程和一些直觉,我想出了下面的简单代码。我知道答案很简单。我似乎无法将其他帖子的答案粘贴到一起,以解决我的问题。非常感谢您提供的任何帮助

我得到“未定义对CreateProcessWithLogonW的引用”错误

#包括
/*声明Windows过程*/
LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM);
HWND文本字段;
/*将类名设置为全局变量*/
char szClassName[]=“WindowsApp”;
int WINAPI WinMain(HINSTANCE Hthis实例,
HINSTANCE HPPrevenstance,
LPSTR LPSZ参数,
int nFunsterStil)
{
这是我们窗口的手柄*/
MSG messages;/*此处保存应用程序的消息*/
windowclass的WNDCLASSEX wincl;/*数据结构*/
/*窗口结构*/
wincl.hInstance=hthis实例;
wincl.lpszClassName=szClassName;
wincl.lpfnWndProc=WindowProcedure;/*此函数由windows调用*/
wincl.style=CS_DBLCLKS;/*捕捉双击*/
wincl.cbSize=sizeof(WNDCLASSEX);
/*使用默认图标和鼠标指针*/
wincl.hIcon=加载图标(空,IDI_应用程序);
wincl.hIconSm=加载图标(空,IDI_应用程序);
wincl.hCursor=LoadCursor(空,IDC_箭头);
wincl.lpszMenuName=NULL;/*无菜单*/
wincl.cbClsExtra=0;/*窗口类后没有额外字节*/
wincl.cbWndExtra=0;/*结构或窗口实例*/
/*使用Windows的默认颜色作为窗口的背景*/
wincl.hbrBackground=GetSysColorBrush(彩色);
/*注册窗口类,如果失败,退出程序*/
if(!RegisterClass(&wincl))
返回0;
/*类已注册,让我们创建程序*/
hwnd=CreateWindowEx(
0,/*变化的扩展可能性*/
szClassName,/*Classname*/
“在火星上打开的文件”,/*标题文本*/
WS_SYSMENU,/*默认窗口*/
CW_USEDEFAULT,/*Windows决定位置*/
CW_USEDEFAULT,/*窗口在屏幕上结束*/
444,/*程序宽度*/
175、/*和高度(以像素为单位)*/
HWND_DESKTOP,/*该窗口是桌面的子窗口*/
空,/*无菜单*/
hThisInstance,/*程序实例处理程序*/
NULL/*无窗口创建数据*/
);
/*使窗口在屏幕上可见*/
显示窗口(hwnd、nFunsterStil);
/*运行消息循环。它将一直运行,直到GetMessage()返回0*/
while(GetMessage(&messages,NULL,0,0))
{
/*将虚拟密钥消息转换为字符消息*/
翻译消息(和消息);
/*向WindowProcedure发送消息*/
DispatchMessage(&messages);
}
/*程序返回值为0—PostQuitMessage()给出的值*/
返回messages.wParam;
}
/*此函数由Windows函数DispatchMessage()调用*/
LRESULT回调窗口过程(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM)
{
开关(消息)/*处理消息*/
{
案例WM_创建:
CreateWindow(文本(“按钮”)、文本(“打开文件”),
WS|u可见| WS|u儿童,
10,10,80,25,
hwnd,(HMENU)1,空,空
);
textfield=CreateWindow(“静态”,
“请单击按钮检索服务器上打开的文件列表”,
WS|u可见| WS|u儿童,
10,50400,25,hwnd,空,空,空);
textfield=CreateWindow(“静态”,
“框底消息”,
WS|u可见| WS|u儿童,
10120400,25,hwnd,NULL,NULL,NULL);
打破
case WM_命令:
如果(LOWORD(wParam)==1){
CreateProcessWithLogonW(L“me”,L“company”,L“xxxxxx”,0,0,L“c:\\files.cmd”,0,NULL,NULL,NULL,NULL);
MessageBox(hwnd,“一个包含所有打开文件的文本文件已放在桌面上”,“打开文件”,MB_OK | MB_图标信息);
}
打破
案例WM_销毁:
PostQuitMessage(0);/*向消息队列发送WM_QUIT*/
打破
默认值:/*用于我们不处理的邮件*/
返回DefWindowProc(hwnd、message、wParam、lParam);
}
返回0;
}
根据,
CreateProcessWithLogonW
Advapi32.lib
中定义。您需要将该库传递给链接器

#include <windows.h>


/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

HWND textfield;


/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = GetSysColorBrush (COLOR_3DFACE);

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Files open on Mars",/* Title Text */
WS_SYSMENU, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
444, /* The programs width */
175, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{

case WM_CREATE:

CreateWindow(TEXT("button"), TEXT("Open files"),
WS_VISIBLE | WS_CHILD,
10,10,80,25,
hwnd, (HMENU) 1, NULL, NULL
);

textfield = CreateWindow("STATIC",
"Please click the button to retrieve a list of open files on server",
WS_VISIBLE | WS_CHILD,
10,50,400,25, hwnd, NULL, NULL, NULL); 

textfield = CreateWindow("STATIC",
"Message at bottom of box",
WS_VISIBLE | WS_CHILD,
10,120,400,25, hwnd, NULL, NULL, NULL); 

break;

case WM_COMMAND:

if (LOWORD(wParam) == 1) {


CreateProcessWithLogonW(L"me", L"company", L"xxxxxx", 0, 0, L"c:\\files.cmd", 0, NULL, NULL, NULL, NULL); 
MessageBox(hwnd, "A text file with all of the open files has been placed on your desktop", "Open Files", MB_OK | MB_ICONINFORMATION);

}



break;

case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}