I have searched and cannot find anything that answers my question. If the phrasing of my question is incorrect please advise and I will rephrase it. I do not profess to be an expert in pointers, but what I am doing seems fairly straight forward and within the guidance provided here:
Pointers and Pointer Types (Delphi)
I have a DLL written in Delphi. It is called from a C++ application (sfms_trayicon.exe). The function in question is of type Pointer and it has one parameter, a pointer. The pointer is passed as a generic pointer and then cast to a hWnd pointer. It is then de-referenced to a variable of type hWnd. Here is the actual function code:
function sfms_ui_init(FhWnd: Pointer): Pointer;
var
pCallinghWnd: ^hWnd; // hWnd pointer type
begin
try
// Get the hWnd passed as a generic pointer
pCallinghWnd := FhWnd; // Cast the general pointer to a hWnd pointer
CallinghWnd := pCallinghWnd^; // De-reference the pointer (CallinghWnd is a global var of type hWnd)
finally
end;
end;
The pointer passed to the function is valid. The assignment to a hWnd pointer type works. The de-referncing occasionally works, but most times generates and access violation:

My question, and I hope it is specific enough, why would the line de-referencing the pointer work occasionally, but most times throw an access violation? I guess the follow up would be, what do I need to do to make it work?
Thanks
register) or that you are not passing what you think you are passing. For instance, it is surely a mistake to pass the address of a variable holding anHWND. Pass anHWNDby value. Also, your function does not return anything, despite promising to do so.