首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

dev c++编译时链接疏失

2012-06-24 
dev c++编译时链接出错程序很简单,从一个控制台应用程序中弹出一个windows对话框。但编译时总是出错,请指点

dev c++编译时链接出错
程序很简单,从一个控制台应用程序中弹出一个windows对话框。但编译时总是出错,请指点
编译错误如下:

  [Linker error] undefined reference to `GetOpenFileNameA@4' 
  [Linker error] undefined reference to `CommDlgExtendedError@0' 
  ld returned 1 exit status 
 C:\Program Files\DEV-CPP\工程\Makefile.win [Build Error] [condlg.exe] Error 1 

源代码如下:
//////////////////////////////////////////
// ConDlg.cpp
// Copyleft 1999 skyline
// How to pop up a GUI dialog from inside a console
//////////////////////////////////////////

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <commdlg.h>
#pragma warning (disable:4068)

//////////////////////////////////////////
// GetFileName
//////////////////////////////////////////
LPSTR GetFileName(HWND hWnd,LPSTR szFile,int StringSize)
{
  OPENFILENAME ofn;
  char szFileTitle[256];
  char szFilter[256];

  strcpy(szFilter,"All Files");
  strcpy(&szFilter[strlen(szFilter)+1],"*.*");
  strcpy(szFileTitle,"Long File Name Search");
  szFile[0]=0;

  memset(&ofn,0,sizeof(OPENFILENAME));

  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = hWnd;
  ofn.lpstrFilter = szFilter;
  ofn.nFilterIndex = 1;
  ofn.lpstrFile = szFile;
  ofn.nMaxFile = StringSize;
  ofn.lpstrTitle = szFileTitle;
  ofn.Flags = OFN_FILEMUSTEXIST;

  if(GetOpenFileName(&ofn)!=TRUE)
  {
DWORD Errval;
char Errstr[50]="Comman Dialog Error: ";
char buf[5];
Errval=CommDlgExtendedError();
if(Errval!=0)
{
wsprintf(buf,"%ld",Errval);
strcat(Errstr,buf);
MessageBox(NULL,Errstr,"Warning",MB_OK|MB_ICONSTOP);
}
  }
  return szFile;
}

//////////////////////////////////////////
// Program Entry Point
//////////////////////////////////////////
int main(void)
{
  char FileName[MAX_PATH*2];
  HWND hWnd;

  printf("Press any key to see dialog");
  _getch();

  hWnd=GetForegroundWindow();

  GetFileName(hWnd,FileName,MAX_PATH*2);

  printf("\n\nYou choose: %s",FileName);

  _getch();
}


[解决办法]
没加库文件

连接命令里加 -lcomctl32
[解决办法]
工程属性->参数->linker加上:-lgdi32 -lcomdlg32
[解决办法]
-lcomctl32

热点排行