Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mixed language programming DLL , C++, VB/VBA, Fortran

Mixed language programming DLL , C++, VB/VBA, Fortran

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jack R
    wrote on last edited by
    #1

    I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:

    M R 2 Replies Last reply
    0
    • J Jack R

      I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:

      M Offline
      M Offline
      markkuk
      wrote on last edited by
      #2

      CString is a MFC class, I don't think you can use CString parameters from VB or Fortran. Change your parameter to char*.

      1 Reply Last reply
      0
      • J Jack R

        I need to create a DLL from C++ and call some of its functions from VB/VBA and Fortran. While creating the DLL I used/tried the /Gz option and also ' extern "C" ' The code below causes runtime error 453 although the function has been exported as int ExtractInt(CString &Line) Declare Function ExtractInt Lib "MyDll.dll" (ByRef Line) As Integer // 'Line' is a CString and will be modified by ExtractInt Function TestExtractInt() As Integer Dim ValInt As Integer Dim Text As String Text = "12 Jack 3" ValInt = ExtractInt(Text) // Should be 12 TxtRet = Text // Should be " Jack 3" TextExtractInt = ValInt End Function Questions: a) Where can I find documentation that describes how to call DLLs written in C++ from VB (especially if MFC and CStrings are involved)? b) What is wrong with my code?:confused:

        R Offline
        R Offline
        realJSOP
        wrote on last edited by
        #3

        a) I would look on the MSDN CD's first. If you can't find it there, a decent advanced book about VB would probably have the info you need. Your DLL can use MFC (statically linked is my advice), but it cannot be an extension DLL (it must be a "regular" DLL). You also cannot use CStrings as parameters or return values. b) I don't know anything about VB, so I can't answer that. c) You might look into writing an ATL COM DLL. It's supposed to be much easier to use from disparate languages (assuming you can use a COM DLL from within your fortran app - if not, forget this option). "...the staggering layers of obcenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups