GetProcAdress returns valid pointer but execution returns: "External exception:" lazarus / 21-General ---------------------------------------------------------------------- Shpend · 2022-01-14 14:42 Title. this is the function and i just cant see why Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function LoadCOMLib: string;  var    funcPtr: InputToStrFunc;  //the definition of this is: function():integer; //sometimes even added with stdcall or cdecl still no work..    path: string;    handleToLib: HWND;    funcReturn: integer;  begin    GetDir(0, path);    path := Concat(path, '\', 'UnmanagedExport__TEST.dll');    handleToLib := LoadLibrary(PChar(path));    if handleToLib <> NilHandle then    begin      try        funcPtr := InputToStrFunc(GetProcAddress(handleToLib, 'AllocRecord'));        //funcPtr('TEST', funcReturn);        funcReturn := funcPtr();        Result := IntToStr(funcReturn);        RaiseLastWin32Error;        //result = Concat(result, 'A');        //result := 'YEEAAA it works' + IntToStr(funcReturn);      except        on e: Exception do        begin          FreeLibrary(handleToLib);          Result := e.Message;        end;      end;    end    else      Result := 'Er hat die Library nicht gefunden irgendwie';  end;           Much appreciation if any1 has a glimpse why. BTW: i try to import a .NET 6 assembly (with .net 6 features) but there is a project on github allowing do use [DllExport] and i followed everys tep carefully like he does in this video: https://www.youtube.com/watch?v=QXMj9-8XJnY https://github.com/3F/Conari Idk .. ---------------------------------------------------------------------- Shpend · 2022-01-14 15:20 Small Addition: OS: windows 10 x64 latest version (21h2) FPC: 3.3.1 (trunk) ; x64 setting, O0 optimization Lazarus 2.3.0 (trunk) ---------------------------------------------------------------------- 440bx · 2022-01-14 15:29 You're not testing the value returned by GetProcAddress.  That would be the first thing to do, otherwise FuncPtr may be nil. HTH. ---------------------------------------------------------------------- engkin · 2022-01-14 15:41 AllocRecord signature? InputToStrFunc definition? ---------------------------------------------------------------------- Shpend · 2022-01-14 15:42 it is not nil @440bx it has an arbitrary adress. i see it via the debugger. ---------------------------------------------------------------------- Shpend · 2022-01-14 15:43 here the image ---------------------------------------------------------------------- Shpend · 2022-01-14 15:44 And yea, there is written the "cdecl" but i have written it with sdtcall, then without any conventions, all the same.. here the value: ---------------------------------------------------------------------- engkin · 2022-01-14 16:00 Still, AllocRecord signature? ---------------------------------------------------------------------- engkin · 2022-01-14 16:03 You need to be sure they match. Same signature, same size Result, same calling convention, and no prerequisites prior to calling. ---------------------------------------------------------------------- Shpend · 2022-01-14 16:04 here ---------------------------------------------------------------------- engkin · 2022-01-14 16:37 According to this example you should use cdecl ---------------------------------------------------------------------- Shpend · 2022-01-14 18:14 ok. I have changed it back again to use "cdecl" in function-variable, and i have talked to the guy who provided the "DllExport" attribute, and he suggested me to change some configuration stuff, and now atleast i get this: (see image below) why is the address 000000000? now, indeed, the functionPointer gives back nill... I changed some stuff with his "Configurator-Tool" (u dont have controll over that sadly so u cant give me hints anyway^^) but curious... ---------------------------------------------------------------------- Akira1364 · 2022-01-14 19:26 I think in C#, `int` is always 4 bytes (so equivalent to LongInt, not Int64). Edit: Also, why are you unconditionally calling `RaiseLastWin32Error`? That will just always raise an exception, and on top of that you're already inside of a try-finally block there... ---------------------------------------------------------------------- marcov · 2022-01-14 23:37 Dump the tables using objdump or a GUI program like PE explorer. Check the export tables there., ---------------------------------------------------------------------- Shpend · 2022-01-15 00:54 Quote from: marcov on January 15, 2022, 12:37:28 amDump the tables using objdump or a GUI program like PE explorer. Check the export tables there., see image. sadly, i have little knowledge of such measurements, would be really nice if you guys could help me understand what it says ---------------------------------------------------------------------- Shpend · 2022-01-15 01:24 take this image now pls, i have created a new project and did some adjusments, atleast now i get back a valid and found lib and a proc- adress! its no longer nil! But same issue as my first post: External Exception 0434352 ---------------------------------------------------------------------- engkin · 2022-01-15 01:28 32bit or 64bit dll? ---------------------------------------------------------------------- engkin · 2022-01-15 01:32 Would be nice if you explain the adjusments you did? ---------------------------------------------------------------------- Shpend · 2022-01-15 01:41 @engkin: I have to appologize for my stupidness sometimes, I fixed it and made it work I pepega took a x86 .dll (i had it set some ages ago in my setting -.-- and forgot to change it back to x64...) into pascal folder where the default target of the compiler only understands x86... So yea... Sry for that, i need to be more careful on the surrounding-settings before i start coding a programm/Idea, I always tend to take that to lightweight and forget the smallest thing when coding are often settings/configurations. ---------------------------------------------------------------------- Shpend · 2022-01-15 01:42 Can actually some1 tell me: Why cant FPC understand a x86 library? or execute my function of such a lib/.dll? since 32-bit is less than 64 ofc, and since im not asking more than the environment allows to, he should be fine right? i dont understand that quite. ---------------------------------------------------------------------- engkin · 2022-01-15 01:51 Glad it works. As for your question, it is not an FPC problem. Typically 32bit applications deal 32bit dlls. Same for 64bit apps/dlls. ---------------------------------------------------------------------- Shpend · 2022-01-15 02:02 Ok, thx @engkin, apparently this is a deep-OS-thing for conventional benefits or the like I guess..