Я пытаюсь выделить память для массива структур, но после того, как она выделена, для int, переданного в функцию, устанавливается значение '0' ... Проблема исчезла, когда я увеличил размер массива , Вот мой код:
wchar_t* ISTFallSensor::JSON_EventLog(int nRecords) {
wchar_t* returnstring = new wchar_t[8192]; memset( returnstring, 0, 8192 * sizeof(TCHAR) );
HINSTANCE hIstDLL;
DWORD (*IST_Open)(TCHAR *, HANDLE *) = 0;
DWORD (*IST_Close)(HANDLE) = 0;
DWORD (*IST_GetMotionEventLogCount)(HANDLE, DWORD, PDWORD) = 0;
DWORD (*IST_GetMotionEventLogRecords)(HANDLE, IST_LOG_RECORD[], int, PINT) = 0;
hIstDLL = LoadLibrary(L"ISTAPI32.dll");
if(hIstDLL && nRecords > 0 ){
IST_Open = (DWORD (__cdecl *)(TCHAR *, HANDLE *))GetProcAddress(hIstDLL, L"IST_Open");
IST_Close = (DWORD (__cdecl *)(HANDLE))GetProcAddress(hIstDLL, L"IST_Close");
IST_GetMotionEventLogCount = (DWORD (__cdecl *)(HANDLE, DWORD, PDWORD))GetProcAddress(hIstDLL, L"IST_GetMotionEventLogCount");
IST_GetMotionEventLogRecords = (DWORD (__cdecl *)(HANDLE, IST_LOG_RECORD[], int, PINT))GetProcAddress(hIstDLL, L"IST_GetMotionEventLogRecords");
HANDLE phIst = INVALID_HANDLE_VALUE;
DWORD openStatus = IST_Open( _T("IST1:"), &phIst );
if ( openStatus == IST_ERROR_SUCCESS ) {
DWORD dropsD; IST_GetMotionEventLogCount(phIst, FREEFALL, &dropsD);
int drops = (int)dropsD;
if ( nRecords > drops ) nRecords = drops; if ( nRecords > 32 ) nRecords = 32;
int pnRecords = 0;
IST_LOG_RECORD eventlog[32] = {0};
DWORD getStatus = IST_GetMotionEventLogRecords(phIst, eventlog, drops, &pnRecords);
Последняя функция получает список событий и использует данный массив для хранения этой информации. Когда функция возвращает массив заполнен правильно, но значение nRecords перезаписывается на «0».
Кто-нибудь знает, что я здесь не так делаю?