3

I currently have a Delphi DLL which takes in 2 parameters as PChar and another parameter that outputs as a PChar to Excel. In Excel these are all string, but whenever I run the macro in Excel, my Excel crashes and restarts.

This is what is in Delphi:

procedure P_GERGDLL(T, rho: double;NID: integer;KIDstr,Xstr:PChar;var Z,P,dP_dT,dP_drho,dP_dV,dV_dT,drho_dT:  double;var XXstr:PChar; var ier: integer); stdcall;

This is what is in VBA:

 Declare PtrSafe Sub P_GERGDLL Lib "C:\Users\louis chapoy\test DLL\Win64\Debug\ThermophiDLL.dll" _
    (ByVal T As Double, ByVal rho As Double, ByVal NID As Integer, ByVal KSTR As String, _
     ByVal Xstr As String, ByRef Z As Double, ByRef P As Double, ByRef dpdt As Double, _
     ByRef dpdr As Double, ByRef dpdv As Double, ByRef dvdt As Double, ByRef drdt As Double, ByRef XXstr As String, ByRef ier As Integer)

P_GERGDLL T, rho, NZ, KIDstr, Xstr, Z, PP, dpdt, dpdr, dpdv, dvdt, drdt, XXstr, ier

I feel like I have tried everything to get this to work, and no matter what different variable types I use it always crashes. They are both 64-bit, and the file locations are correct. I have shareMem at the top of my uses clause.

8
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Sep 4 at 19:58
  • 1
    Out of curiosity. Can you try WideString instead of PChar? Commented Sep 4 at 20:19
  • Related: stackoverflow.com/questions/39404028 Note that question is about C++ but the exact same problem applies to Delphi, too. Commented Sep 5 at 8:45
  • i have tried both PChar and WideString. I think i need to use an xll file in the middle since delphi 12 doesnt really like when passing string. Commented Sep 5 at 12:54
  • 7
    This is not how Stack Overflow works - we're not here to work for you. If you have an answer to your question, then post one with code for both languages that now works for you. That'll help future readers (instead of letting them know that you'll keep the details to yourself). Commented Sep 5 at 17:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.