| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 494 人关注过本帖
标题:[求助]编译通过,却无法连接
只看楼主 加入收藏
Playboygdcn
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-3-2
收藏
 问题点数:0 回复次数:0 
[求助]编译通过,却无法连接
[求助]编译通过,却无法连接。
此主题相关图片如下:
图片附件: 游客没有浏览图片的权限,请 登录注册


GetFileVersionInfoSize(filename,&dwHandle);
BOOL bret = GetFileVersionInfo(filename,dwHandle,cchver,pver);
bret = VerQueryValue(pver,"\\",&pbuf,&uLen);
这三个是API函数啊。
库函数是Version.dll
为什么还是不能连接呢?


// checkversion.cpp
// compile with: /link version.lib

#include <windows.h>
#include <stdio.h>

void EmitErrorMsg (HRESULT hr);
HRESULT GetFileVersion (char *filename, VS_FIXEDFILEINFO *vsf);
HRESULT GetFileDate (char *filename, FILETIME *pft);
HRESULT LastError();
int WhichIsNewer (char *fname1, char *fname2);

void printtime (FILETIME *t) {

FILETIME lft;
FILETIME *ft = &lft;
FileTimeToLocalFileTime(t,ft);
printf("%08x %08x",ft->dwHighDateTime,ft->dwLowDateTime); {
SYSTEMTIME stCreate;
BOOL bret = FileTimeToSystemTime(ft,&stCreate);
printf(" %02d/%02d/%d %02d:%02d:%02d\n",
stCreate.wMonth, stCreate.wDay, stCreate.wYear,
stCreate.wHour, stCreate.wMinute, stCreate.wSecond);
}
}

int main(int argc, char* argv[]) {
printf("usage: checkversion file1 file2\n"
"\tReports which file is newer, first by checking the file version in "
"\tthe version resource, then by checking the date\n\n" );

if (argc != 3)
return 1;

int newer = WhichIsNewer(argv[1],argv[2]);
switch(newer) {
case 1:
case 2: printf("%s is newer\n",argv[newer]); break;
case 3: printf("they are the same version\n"); break;
case 0:
default: printf("there was an error\n"); break;
}

return !newer;
}

int WhichIsNewer (char *fname1, char *fname2) {
// 1 if argv[1] is newer
// 2 if argv[2] is newer
// 3 if they are the same version
// 0 if there is an error

int ndxNewerFile;
HRESULT ret;
VS_FIXEDFILEINFO vsf1,vsf2;

if ( SUCCEEDED((ret=GetFileVersion(fname1,&vsf1))) && SUCCEEDED((ret=GetFileVersion(fname2,&vsf2)))) {
// both files have a file version resource
// compare by file version resource
if (vsf1.dwFileVersionMS > vsf2.dwFileVersionMS) {
ndxNewerFile = 1;
}
else
if (vsf1.dwFileVersionMS < vsf2.dwFileVersionMS) {
ndxNewerFile = 2;
}
else { // if (vsf1.dwFileVersionMS == vsf2.dwFileVersionMS)
if (vsf1.dwFileVersionLS > vsf2.dwFileVersionLS) {
ndxNewerFile = 1;
}
else if (vsf1.dwFileVersionLS < vsf2.dwFileVersionLS) {
ndxNewerFile = 2;
}
else { // if (vsf1.dwFileVersionLS == vsf2.dwFileVersionLS)
ndxNewerFile = 3;
}
}
}

else {
// compare by date
FILETIME ft1,ft2;
if (SUCCEEDED((ret=GetFileDate(fname1,&ft1))) && SUCCEEDED((ret=GetFileDate(fname2,&ft2))))
{
LONG x = CompareFileTime(&ft1,&ft2);
if (x == -1)
ndxNewerFile = 2;
else
if (x == 0)
ndxNewerFile = 3;
else
if (x == 1) ndxNewerFile = 1;
else {
EmitErrorMsg(E_FAIL);
return 0;
}
}
else {
EmitErrorMsg(ret);
return 0;
}
}
return ndxNewerFile;
}

HRESULT GetFileDate (char *filename, FILETIME *pft) {
// we are interested only in the create time
// this is the equiv of "modified time" in the
// Windows Explorer properties dialog
FILETIME ct,lat;
HANDLE hFile = CreateFile(filename,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (hFile == INVALID_HANDLE_VALUE)
return LastError();
BOOL bret = GetFileTime(hFile,&ct,&lat,pft);
if (bret == 0)
return LastError();
return S_OK;
}

// This function gets the file version info structure
HRESULT GetFileVersion (char *filename, VS_FIXEDFILEINFO *pvsf) {
DWORD dwHandle;
DWORD cchver = GetFileVersionInfoSize(filename,&dwHandle);
if (cchver == 0)
return LastError();
char* pver = new char[cchver];
BOOL bret = GetFileVersionInfo(filename,dwHandle,cchver,pver);
if (!bret)
return LastError();
UINT uLen;
void *pbuf;
bret = VerQueryValue(pver,"\\",&pbuf,&uLen);
if (!bret)
return LastError();
memcpy(pvsf,pbuf,sizeof(VS_FIXEDFILEINFO));
delete[] pver;
return S_OK;
}

HRESULT LastError () {
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
if (SUCCEEDED(hr))
return E_FAIL;
return hr;
}

// This little function emits an error message based on WIN32 error messages
void EmitErrorMsg (HRESULT hr) {
char szMsg[1024];
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
szMsg,
1024,
NULL
);
printf("%s\n",szMsg);
}



[此贴子已经被作者于2006-3-2 17:13:12编辑过]

搜索更多相关主题的帖子: 编译 
2006-03-02 17:07
快速回复:[求助]编译通过,却无法连接
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042145 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved