Thread: C# and DLL passing and retrieving data

  1. #1
    Registered User
    Join Date
    Nov 2009

    C# and DLL passing and retrieving data


    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.
            public static extern int ReadNetwork(Byte[] ROM_ID);
    Below is the code in the DLL
    int _stdcall ReadNetwork(unsigned char* Array1)
    	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.

    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
    how does the ReadNetwork function in the DLL know how big the array is?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    why are you allocating 12 bytes when function fills 20?

    See samples using StringBuilder
    C# and the char* mess
    To be or not to be == true

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, 11:37 AM
  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, 07:44 AM
  4. Retrieving Browser Data
    By Siphon in forum C++ Programming
    Replies: 2
    Last Post: 04-07-2008, 07:31 AM
  5. retrieving data from listboxes
    By luddeb in forum Windows Programming
    Replies: 6
    Last Post: 01-10-2006, 04:08 AM