|
|
一个控制台应用程序,释放IDirectPlay8Client对象出错,不知是何原因,
错误信息:Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
程序如下。
需要的库文件:dxguid.lib
#include "stdafx.h"
#include <dplay8.h>
#include <dpaddr.h>
//dxguid.lib odbc32.lib odbccp32.lib
IDirectPlay8Client *g_pDP=NULL;
HRESULT WINAPI MessageHandler(PVOID pvUserContext,DWORD dwMessageId,PVOID pMsgBuffer)
{
// Return S_OK to signify the message was handled OK
return S_OK;
}
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
CoInitialize(NULL);
// Create the IDirectPlay8Peer Object
hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP);
// Initialize DirectPlay
hr = g_pDP->Initialize(NULL, MessageHandler, 0);
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfoEnum = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
DWORD i;
// Determine the required buffer size
hr = g_pDP->EnumServiceProviders(NULL, NULL, NULL, &dwSize, &dwItems, 0);
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
//Fill the buffer with service provider information
hr = g_pDP->EnumServiceProviders(NULL, NULL, pdnSPInfo, &dwSize, &dwItems, 0);
// Print the provider descriptions
pdnSPInfoEnum = pdnSPInfo;
for (i = 0; i < dwItems; i++)
{
printf("Found Service Provider: %S\n", pdnSPInfoEnum->pwszName);
pdnSPInfoEnum++;
}
// Release client component这里出错
if(g_pDP != NULL) {
g_pDP->Close(0);
g_pDP->Release();
}
g_pDP = NULL;
CoUninitialize();
return 0;
}
|
|