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. Visual Basic
  4. Call By Reference in C++ DLL from VB

Call By Reference in C++ DLL from VB

Scheduled Pinned Locked Moved Visual Basic
helpc++tutorial
5 Posts 2 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.
  • P Offline
    P Offline
    PremalathaP
    wrote on last edited by
    #1

    Hello, I have developed an application to call a C++ DLL from VB. If I send the values to the functions of DLL as Call By Value method, it gives correct output. If I do the same through Call By Reference method, it gives improper values as result. For example, Instead of printing 47000, it prints the value 2.55471e-041. Please help me to clear this problem. Premalatha

    D 1 Reply Last reply
    0
    • P PremalathaP

      Hello, I have developed an application to call a C++ DLL from VB. If I send the values to the functions of DLL as Call By Value method, it gives correct output. If I do the same through Call By Reference method, it gives improper values as result. For example, Instead of printing 47000, it prints the value 2.55471e-041. Please help me to clear this problem. Premalatha

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Please tell me you rewrote the C++ function to accept a parameter pass by reference? Without changing BOTH the C function and the VB Declaration, you're trying to fit a square peg in a round hole. If the C++ function is expecting a parameter passed by value, you obviously can't pass in a reference to it. The opposite is also true... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Please tell me you rewrote the C++ function to accept a parameter pass by reference? Without changing BOTH the C function and the VB Declaration, you're trying to fit a square peg in a round hole. If the C++ function is expecting a parameter passed by value, you obviously can't pass in a reference to it. The opposite is also true... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        P Offline
        P Offline
        PremalathaP
        wrote on last edited by
        #3

        FloatPtr = & max_ceiling; for(i=2; i<7; i++, FloatPtr++) *FloatPtr = atof(GetValue(instr,s,128)); This code i wrote in C++ within a function. max_ceiling is the array. GetValue is a function which reads single line from the binary file(instr) and converts to value to update in text file. In this for loop, i have to get values like 47000 516 0.63 3000 100. But i am getting the values as 2.55471e-041, 89224, -2.26464e-041, 2.48352e-041,2.07628e-040 This is my problem

        D 1 Reply Last reply
        0
        • P PremalathaP

          FloatPtr = & max_ceiling; for(i=2; i<7; i++, FloatPtr++) *FloatPtr = atof(GetValue(instr,s,128)); This code i wrote in C++ within a function. max_ceiling is the array. GetValue is a function which reads single line from the binary file(instr) and converts to value to update in text file. In this for loop, i have to get values like 47000 516 0.63 3000 100. But i am getting the values as 2.55471e-041, 89224, -2.26464e-041, 2.48352e-041,2.07628e-040 This is my problem

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          This isn't enough to diagnose the problem. You have to post the function header that is defined in the C++ code. Yout also have to post the VB Declare statement that defines how VB passes parameters. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          P 1 Reply Last reply
          0
          • D Dave Kreskowiak

            This isn't enough to diagnose the problem. You have to post the function header that is defined in the C++ code. Yout also have to post the VB Declare statement that defines how VB passes parameters. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            P Offline
            P Offline
            PremalathaP
            wrote on last edited by
            #5

            VB: Private Declare Function FirstMethod Lib "C:\Premalatha\C++\17_01_06-ACDB_CON_DLL\Debug\ACDB_CON.dll" (ByVal ArgCount As Integer, ByVal Args0 As String, ByVal Args1 As String, ByVal Args2 As String, ByVal Args3 As String) As Boolean C++: #include #include "acdbcon.hpp" #include using namespace std; bool __stdcall FirstMethod(int argc,char argv0[],char argv1[],char argv2[],char argv3[]) { char *argv[4]; argv[0]=argv0; argv[1]=argv1; argv[2]=argv2; argv[3]=argv3; MessageBox(NULL,argv[0],"Filename",NULL); MessageBox(NULL,argv[1],"Input",NULL); MessageBox(NULL,argv[2],"Output",NULL); MessageBox(NULL,argv[3],"Choice",NULL); CAcdbCon Con; Con.ACDBmain(argc,argv); return true; } ----------------------------------------------------------------------------- void CAcdbCon::ACDBmain(int argc, char * argv[]) //JLF 10/30/02 { MessageBox(NULL,"Con:ACDBMain","Func",NULL); //***************** NOTICE NOTICE NOTICE ***************************** // Always update Software version and the date the changes were made // for ANY changes made to the tool. For minor changes and fixes, // update the decimal value, whereas major revisions update the // first number const char * Version="2.01"; const char * Date="November 29, 2002"; //Error is true if the the MainEventProcessor method returns with an error, // otherwise it is false. int Error; //MainDriver object which is the user interface driver. CDriver MainDriver(Version,Date); //Start the main processing loop. Error = MainDriver.MainEventProcessor(argc, argv); //Display that the main processing loop is completed (with errors) if(Error) { cout << endl << "Application terminated with errors." << endl; //Pause the screen so the user can see the results int ch = 0; cout << "Type ESC to Exit"; do ch = _getch(); while(ch != 27); //search for ESC character } }; --------------------------------------------------------------------------- int CDriver::MainEventProcessor(int argc, char * argv[]) //(JLF 10/30/02) { MessageBox(NULL,"Driver:MainEvent","Func",NULL); //Flag is set to TRUE as long as processing is necessary. When the user // selects EXIT program then Running is set to FALSE. int Running = 1; //Operating mode. BATCHMODE reads a script file to control the program. // INTERACTIVEMODE allows the user to interactively control the program. // COMMANDMODE the user has entered

            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