loading an existing dll

2 views (last 30 days)
JH
JH on 28 Aug 2013
Hi all-
I want write a C++ s-function that accesses/loads an existing dll. I have an existing example calling the dll using fortran:
REAL(4) :: avrSWAP(*)
INTEGER(4) :: aviFAIL
INTEGER(1) :: accINFILE(*)
INTEGER(1) :: avcMSG(*)
INTEGER(1) :: avcOUTNAME(*)
INTEGER(HANDLE) :: FileAddr
INTEGER(LPVOID) :: ProcAddr
POINTER ( DLL_ProcAddr, DLL_Procedure )
INTERFACE
SUBROUTINE DLL_Procedure(avrSWAP,aviFAIL,accINFILE,avcOUTNAME,avcMSG)
REAL(4) :: avrSWAP (*)
INTEGER(4) :: aviFAIL
INTEGER(1) :: accINFILE (*)
INTEGER(1) :: avcMSG (*)
INTEGER(1) :: avcOUTNAME(*)
END SUBROUTINE DLL_Procedure
END INTERFACE
FileAddr = LoadLibrary( "DISCON.DLL" )
ProcAddr = GetProcAddress( DLL_Trgt%FileAddr, "DISCON" )
DLL_ProcAddr = ProcAddr
CALL DLL_Procedure ( avrSWAP, aviFAIL, accINFILE, avcOUTNAME, avcMSG )
Is there an example of doing something similar from a C++ s-function? The interface is clear from the fortran code, but I do not have the header file or the code for this dll. I am quite confident that I can write/hack my own C++ header for it if that is necessary. If anyone wants to take a crack at actually writing the necessary C++ code to load and call the dll, that would be absolutely terrific. Otherwise, just a simple example of a C++ s-function calling any dll would be fantastic as well.
Thanks for any and all help,
-Jason
  1 Comment
Kaustubha Govind
Kaustubha Govind on 28 Aug 2013
JH: S-functions support standard C usage (I think it's the C99 standard, but it probably depends on what MEX compiler you're using), so I would recommend that you attempt to first write standalone C/C++ code that uses the DLL outside of MATLAB, and test it out. Once you have that working, you can use the same type of call in an S-function.

Sign in to comment.

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!