+ Reply to Thread
Results 1 to 11 of 11

How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

  1. #1
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29

    How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Now, I'm currently trying to receive the multiple return value from DLL in VBA(Excel Visual Basic).

    This is my DLL code.

    Please Login or Register  to view this content.
    Then I want to give some value to the DLL by using the datain0 and datain1 and receive the dataout0 and dataout1 from the DLL in the VBA(Excel Visual Basic).

    This is my VBA code.actually, I'm not familiar with VBA(Excel Visual Basic)

    Please Login or Register  to view this content.
    What am I supposed to make the function which is what I want to give datain0=3, datain1=4 and receive the dataout0 and dataout1 values?
    If I run the above code in the excel, I've got a problem halt
    Last edited by u24c02; 03-10-2017 at 08:50 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,331

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Your dll function is modifying the variables passed to it using ByRef (data2 and data3) so your function pll_dll_excel should return those values as an array instead of passing the returned 0 from the dll. This is how you should be using the ByRef variables - I have just created a fake pll_dll function for demonstration.... when you pass Cells() you are only passing the value and not the cell object so you cannot write directly to it.

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 03-10-2017 at 01:03 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29
    [QUOTE=Bernie Deitrick;4602389]Your dll function is modifying the variables passed to it using ByRef (data2 and data3) so your function pll_dll_excel should return those values as an array instead of passing the returned 0 from the dll. This is how you should be using the ByRef variables - I have just created a fake pll_dll function for demonstration.... when you pass Cells() you are only passing the value and not the cell object so you cannot write directly to it.

    Please Login or Register  to view this content.
    Is this correct?
    Last edited by u24c02; 03-11-2017 at 12:04 PM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,331

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    No.

    You cannot have a Function Sub ("Function Sub useSquareInVBA() ")

    Try just using the dll function directly - your dll already uses ByRef:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Quote Originally Posted by Bernie Deitrick View Post
    No.

    You cannot have a Function Sub ("Function Sub useSquareInVBA() ")

    Try just using the dll function directly - your dll already uses ByRef:

    Please Login or Register  to view this content.


    Dear Bernie,
    your answer work as well,
    So I've just added the one more parameter in the C DLL module as the below,

    Please Login or Register  to view this content.
    and the below is the EXCEL VBA code, I've just added "char * str" but in this case,
    I've got program halt when I run.

    Please Login or Register  to view this content.
    how can I get the string and char type data from dll?

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,331

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Have you updated your declaration line?

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Quote Originally Posted by Bernie Deitrick View Post
    Have you updated your declaration line?

    Please Login or Register  to view this content.
    Dear Bernie,
    This is my C code
    q8.JPG

    ans the below code is the VBA code


    Please Login or Register  to view this content.

    The problem is that I can get the any string data from dll.
    Would you please help me please?
    Last edited by u24c02; 03-13-2017 at 11:28 AM.

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,331

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29
    Quote Originally Posted by Bernie Deitrick View Post
    Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.


    Thanks, but both the same result.

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,331

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    It might be an issue with C, but I don't know C - sorry. You might want to start a new thread.

  11. #11
    Registered User
    Join Date
    03-10-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    29

    Re: How can I receive the multi return values from DLL in VBA(Excel Visual Basic)?

    Quote Originally Posted by Bernie Deitrick View Post
    It might be an issue with C, but I don't know C - sorry. You might want to start a new thread.
    Thanks Bernie, I got it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel Macro - Visual Basic - Send command to serial port - Receive Data.
    By reiiling in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2017, 09:37 AM
  2. [SOLVED] Can I run Visual Basic procedure using Excel Visual Basic editor?
    By john.jacobs71 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-26-2005, 10:25 AM
  3. Excel in Visual Basic
    By Spike in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2005, 02:15 PM
  4. Visual Basic Multi-Stepped process
    By MK@Hartford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2005, 01:35 PM
  5. Replies: 1
    Last Post: 09-13-2005, 07:06 AM
  6. converting formulas into values using a macro in visual basic edit
    By F.C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2005, 05:05 AM
  7. visual basic in excel -
    By DKehl in forum Excel General
    Replies: 2
    Last Post: 03-23-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1