VS2010 and above causing heap curruption in RPC client call

  • Thread starter Thread starter Jiyang
  • Start date Start date
J

Jiyang

Guest
I got heap corruption in test program as below in VS2010 (it worked fine in VS2008). It happens in last COM call before returning. In VS2010 I can switch platform toolset from v90 to v100 to reproduce this problem in debug/release mode. The same problem exists with VS2019 as well. I can't find any place leading to this corruption. Can anyone help? Thanks!


#pragma once
#include <tchar.h>
#include <comdef.h>
#include <comcat.h>
#include <atlcomcli.h>

#include "opccomn_i.c"
#include "OpcEnum_i.c"
#include "opchda.h"

int _tmain(int argc, _TCHAR* argv[]) {

CoInitializeEx(NULL, COINIT_MULTITHREADED);

CLSID serverCLSID;
CLSIDFromString(CComBSTR("{6A5EEDEC-1509-4627-997F-993CCB65AB7C}"), &serverCLSID);

COSERVERINFO cInfo = { 0 };
cInfo.pwszName = L"localhost";

MULTI_QI cResults = { 0 };
cResults.pIID = &IID_IOPCHDA_Server;

HRESULT hr = CoCreateInstanceEx(serverCLSID, NULL, CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, &cInfo, 1, &cResults);
if (FAILED(hr))
return EXIT_FAILURE;


CComPtr<IOPCHDA_Server> server;
server.p = (IOPCHDA_Server*)cResults.pItf;

OPCHANDLE* hServerItem = NULL;
OPCHANDLE hClientItem = 1;
HRESULT* pErrors = NULL;
LPWSTR pszItemID = L"Static Data/Square [15 min]";

hr = server->GetItemHandles(1, &pszItemID, &hClientItem, &hServerItem, &pErrors);
if (FAILED(hr))
return EXIT_FAILURE;


OPCHDA_TIME start, end;
start.bString = true;
start.szTime = L"NOW-18MO";

end.bString = true;
end.szTime = L"NOW";

CComPtr<IOPCHDA_SyncRead> ipOPCHDA_SyncRead;
hr = server->QueryInterface(IID_IOPCHDA_SyncRead, (void**)& ipOPCHDA_SyncRead);
if (FAILED(hr))
return EXIT_FAILURE;


OPCHDA_ITEM* pItemValues = NULL;
HRESULT* pErrors1 = NULL;

hr = ipOPCHDA_SyncRead->ReadRaw(&start, &end, 10, true, 1, hServerItem, &pItemValues, &pErrors1);

//CoUninitialize();
return(EXIT_SUCCESS);
}

1450351.jpg

1450352.jpg


JH

Continue reading...
 
Back
Top