Like Tree1Likes
  • 1 Post By vart

C# and DLL passing and retrieving data

This is a discussion on C# and DLL passing and retrieving data within the C# Programming forums, part of the General Programming Boards category; Hello, I have a C# program going and want to be able to call the DLL and receive back the ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    52

    C# and DLL passing and retrieving data

    Hello,

    I have a C# program going and want to be able to call the DLL and receive back the data requested through a pointer.

    Below is the DLL import within my C# code.
    Code:
    [DllImport("MyTest.dll")]
            public static extern int ReadNetwork(Byte[] ROM_ID);
    Below is the code in the DLL
    Code:
    int _stdcall ReadNetwork(unsigned char* Array1)
    {
    	ReadDevice(readBackArray);
    	for(i = 0; i < 20; i++)
    	{
    		Array1[i] = readBackArray[i];
    	}
    
    	return 1;
    }
    And below how I'mm calling the DLL and trying to print out the results.

    Code:
    int errorCheck;
    byte[] testArray;
    testArray = new byte[12];
    string value;
    
    errorCheck = ReadNetwork(testArray);
    MessageBox.Show("Return Value: " + errorCheck.ToString());
    value = ASCIIEncoding.ASCII.GetString(testArray);
    MessageBox.Show("Array String: " + value);
    I've tried changing the return values in the DLL's ReadNetwork() function and that works ok, so I know I'm calling the DLL and it runs ok, but printing the result back is where I'm having the problem. Any help will be appreciated.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,545
    how does the ReadNetwork function in the DLL know how big the array is?
    Code:
    namespace life
    {
        const bool change = true;
    }

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    why are you allocating 12 bytes when function fills 20?

    See samples using StringBuilder
    C# and the char* mess
    Elkvis likes this.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. retrieving data from a mysql table thorugh c++
    By daehan00 in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2012, 12:37 PM
  2. Retrieving data from a file
    By kamitsuna in forum C++ Programming
    Replies: 45
    Last Post: 02-27-2010, 09:37 PM
  3. Retrieving Data from DLL
    By JJFMJR in forum C++ Programming
    Replies: 11
    Last Post: 08-18-2008, 08:44 AM
  4. Retrieving Browser Data
    By Siphon in forum C++ Programming
    Replies: 2
    Last Post: 04-07-2008, 08:31 AM
  5. retrieving data from listboxes
    By luddeb in forum Windows Programming
    Replies: 6
    Last Post: 01-10-2006, 04:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21