我需要从 DDE 服务器获取数据。在循环的 16000 通行证的某个地方,我得到了 krakozyabry。Visual Studio 2010 速成版,windows xp。在 Delphi 上没有这样的问题。我究竟做错了什么?
UPD:在我看来,内存有问题吗?
#include "stdafx.h"
#include <windows.h>
#include "ddeml.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <fstream>
using namespace std;
#pragma comment(lib, "ws2_32.lib")
HDDEDATA CALLBACK DdeCallback(
UINT uType, // Transaction type.
UINT uFmt, // Clipboard data format.
HCONV hconv, // Handle to the conversation.
HSZ hsz1, // Handle to a string.
HSZ hsz2, // Handle to a string.
HDDEDATA hdata // Handle to a global memory object.
)
{
return 0;
}
char* DDERequest(DWORD idInst, HCONV hConv, char* szItem)
{ char *szResult = new char[255];
HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0);
HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT,
XTYP_REQUEST,999999999 , NULL);
if (hData==NULL)
{
printf("Request failed: %s\n", szItem);
}
else
{
DdeGetData(hData, (unsigned char *)szResult, 255, 0);
// printf("%s%s\n", sDesc, szResult);
}
return szResult;
}
int __cdecl main(void)
{
//-----------------------------------------GET DDE DATA-----------------------------------------
char szApp[] = "EXCEL";
char szTopic[] = "sheet";
int i;
//DDE Initialization
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
if (iReturn!=DMLERR_NO_ERROR)
{
printf("DDE Initialization Failed: 0x%04x\n", iReturn);
}else {printf("DDE Initialization: 0x%04x\n", iReturn);}
//DDE Connect to Server using given AppName and topic.
HSZ hszApp, hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandle(idInst, szApp, 0);
hszTopic = DdeCreateStringHandle(idInst, szTopic, 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
printf("---------------------------------------------DDE Connection Failed.----------------------------------\n");
}else{printf("DDE Connection Succeful.\n");}
//Execute commands/requests specific to the DDE Server.
for (int a=0;a<999999999;a++){
printf("NUMBER ----------------------------%d-------------------------------\n",a);
printf("rezult : %s\n",DDERequest(idInst, hConv, "R1C1"));
}
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
system("pause");
return 1;
}
1 个回答