我正在做一個專案,我有一個要使用的函式串列。我使用提供的 DLL。我在檔案“list.h”中有函式的原型。這個檔案也提供給我
串列.h
typedef unsigned short (__stdcall * ReadConfig)
(void * * pDataOut,
size_t * pSizeDataOut);
我寫了這個main.c
int main (int nbArg, char** listeArg)
{
// Initialization
unsigned short outputFunction;
void * pointerMemoryZone = NULL;
size_t sizeMemoryZone = NULL;
// Load DLL
HMODULE dllLoadOuput= LoadLibrary("dllFile");
// Alias Creation
typedef unsigned short(*A_ReadConfig) (void * *, size_t *);
// Get Pointer on Function
A_ReadConfig ptrReadConfiguration = (A_ReadConfig)GetProcAddress(dllLoadOuput, "ReadConfig");
// Launch of the function
outputFunction = ptrReadConfiguration(&pointerMemoryZone, &sizeMemoryZone);
// Display
printf("\n\nSize Read Config : %ld\n\n", sizeMemoryZone);
// Unload DLL
FreeLibrary(dllLoadOuput);
return 0;
}
這個程式有效,我得到了記憶體區域的大小。
但是我的程式,我的變數是否正確宣告和使用...?
以及如何讀取存盤區中包含的資料...?
下面是檔案中提供的圖表:

uj5u.com熱心網友回復:
假設 outputFunction 表示成功,指標pointerMemoryZone應該包含sizeMemoryZone位元組的資料。
您訪問資料的方式取決于格式(例如 text/json/xml 字串)。
以 ascii 和 hex 顯示資料的示例回圈:
for(int i=0; i<sizeMemoryZone; i ) {
char c = ((char*) pointerMemoryZone)[i];
printf("%c{%x} ", c, c);
}
uj5u.com熱心網友回復:
我回答我的問題。我找到了解決辦法。
我必須逐位元組讀取資料。
因此,我通過將指標型別強制為字符(因為 1 位元組)在“ pointerMemoryZone ”(包含資料地址)上創建了一個字符指標,然后我創建了一個回圈,在其中我一個接一個地回圈遍歷地址(沿著資料)
在回圈代碼下方
//...
//...
//...
// Launch of the function
outputFunction = ptrReadConfiguration(&pointerMemoryZone, &sizeMemoryZone);
// Creation of Pointer
char *pointerOnPointerMemoryZone = NULL;
// Begin Loop
for (int i = 0; i < sizeMemoryZone; i )
{
// Association Pointer to Adress ( 0, 1, 2, etc..)
pointerOnPointerMemoryZone = (char*)pointerMemoryZone i;
printf("\n%d\t\t%d\t\t%c",i, *pointerOnPointerMemoryZone, *pointerOnPointerMemoryZone);
}
// End Loop
//...
//...
//...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/506512.html
