Click here to Skip to main content
15,884,629 members
Home / Discussions / C#
   

C#

 
GeneralRe: When is it safe to use Monitor (lock) with Task? Pin
Pete O'Hanlon18-Jan-17 21:15
mvePete O'Hanlon18-Jan-17 21:15 
QuestionGroup of Checkboxes Pin
eejaynic17-Jan-17 11:41
eejaynic17-Jan-17 11:41 
AnswerRe: Group of Checkboxes Pin
Gerry Schmitz17-Jan-17 13:02
mveGerry Schmitz17-Jan-17 13:02 
GeneralRe: Group of Checkboxes Pin
eejaynic17-Jan-17 14:11
eejaynic17-Jan-17 14:11 
GeneralRe: Group of Checkboxes Pin
Gerry Schmitz17-Jan-17 14:53
mveGerry Schmitz17-Jan-17 14:53 
AnswerRe: Group of Checkboxes Pin
Richard Deeming18-Jan-17 2:04
mveRichard Deeming18-Jan-17 2:04 
GeneralRe: Group of Checkboxes Pin
eejaynic18-Jan-17 9:03
eejaynic18-Jan-17 9:03 
QuestionCommunicating with unmanaged DLL Pin
Member 1041441717-Jan-17 2:43
Member 1041441717-Jan-17 2:43 
I'm trying to convert an old vb.net program into CSharp but I'm having some trouble accessing an unmanaged DLL - the DLL itself is for a NFS reader (CR95HF Demo Kit) and the application note is here:

[^] (a PDF file)

Just as an example I'm trying to access the gethardwareVersion function.

The problem I have is that the example says the declaration should look like

C++
CR95HFDLL_getHardwareVersion(char* StringReply)


and the source that calls this is

C++
char strAnswer[50]="";
int iresult
iresult = CR95HFDLL_GetHardwareVersion(strAnswer)


So far I have:

C#
<pre>namespace RWH_DLL
    {
        /*
         Protected Declare Function CR95HFDLL_USBconnect Lib "CR95HF.dll" () As System.UInt32                                                                    'makes a USB connection
    Protected Declare Function CR95HFDll_Select Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As System.UInt32                   'sets up the protocol ("010D")
    Protected Declare Function CR95HFDll_FieldOff Lib "CR95HF.dll" (ByVal mycmdstring As String) As System.UInt32
    Protected Declare Function CR95HFDLL_USBhandlecheck Lib "CR95HF.dll" () As System.UInt32
    Protected Declare Function CR95HFDll_SendReceive Lib "CR95HF.dll" (ByVal mycmdstring As String, ByVal mystring As String) As System.UInt32

    'not used in code, but may be useful (several more have been removed)
    Protected Declare Function CR95HFDll_ResetSPI Lib "CR95HF.dll" (ByVal mystring As String) As System.UInt32
    Protected Declare Function CR95HFDLL_getHardwareVersion Lib "CR95HF.dll" (ByVal mystring As String) As System.UInt32

    Protected Const CR95HF_STM32_error = &H1
    Protected Const CR95HF_empty_argument_error = &H2
    Protected Const CR95HF_cmd_parameter_error = &H3
    Protected Const CR95HF_communication_error = &H4
    Protected Const CR95HF_USB_communication_error = &H5
    Protected Const CR95HF_ERRORCODE_DEFAULT = &HFE
    Protected Const CR95HF_ERRORCODE_TIMEOUT = &HFD
         
         */
        

        public class RWH
        {

            [DllImport("CR95HF.dll")] 
            public static extern UInt32 CR95HFDLL_USBconnect();
            [DllImport("CR95HF.dll")]
            //public static extern UInt32 CR95HFDll_SendReceive(string commandString, string returnString);
            public static unsafe extern UInt32 CR95HFDLL_getHardwareVersion(char* returnString);
            
            // ByVal mycmdstring As String, ByVal mystring As String
        }
        
    }

    namespace ReadWriteHardware
    {
        //this partial class just holds the singleton stuff to keep it separate from everything else
        public partial class RWHardware
        {
            static RWHardware singleInstance = null;
            static readonly object padlock = new object();

            RWHardware()
            { }

            public static RWHardware Instance
            {
                get
                {
                    lock (padlock)
                    {
                        if (singleInstance == null)
                        {
                            singleInstance = new RWHardware();
                        }

                        return singleInstance;
                    }
                }
            }
        }


        //use this partial class to store all the variables in
        public partial class RWHardware
        {

        }

        //this partial class is where the functions go
        public partial class RWHardware
        {
            public Boolean GetRWBoard()
            { 
                UInt32 blob = 0;
                blob = RWH_DLL.RWH.CR95HFDLL_USBconnect();
                String cmdString = "260100";
                String rtnString = new string(Convert.ToChar(" "), 256);
                //string rtnString = "";
                //blob = RWH_DLL.RWH.CR95HFDll_SendReceive(cmdString,rtnString);
                char[] strAnswer = new char [50];

                blob = RWH_DLL.RWH.CR95HFDLL_getHardwareVersion(strAnswer);
                return false;
            }
        }
    }


I'm struggling swapping between the pointers and the char arrays. I have had simpler functions from the dll working (those that just return a value and have no input). - the stuff in comments is all the functions I am converting and my vb versions of those functions.
AnswerRe: Communicating with unmanaged DLL Pin
Midi_Mick17-Jan-17 3:19
professionalMidi_Mick17-Jan-17 3:19 
GeneralRe: Communicating with unmanaged DLL Pin
Member 1041441717-Jan-17 4:13
Member 1041441717-Jan-17 4:13 
AnswerRe: Communicating with unmanaged DLL Pin
Bernhard Hiller17-Jan-17 23:26
Bernhard Hiller17-Jan-17 23:26 
QuestionRe: Communicating with unmanaged DLL Pin
Member 1390693510-Jul-18 22:01
Member 1390693510-Jul-18 22:01 
QuestionGlade errors after launching debug Pin
Sascha Manns16-Jan-17 23:18
professionalSascha Manns16-Jan-17 23:18 
AnswerRe: Glade errors after launching debug [Solved] Pin
Sascha Manns17-Jan-17 5:41
professionalSascha Manns17-Jan-17 5:41 
QuestionImplementing Strategy Pattern Pin
Liagapi16-Jan-17 22:20
Liagapi16-Jan-17 22:20 
AnswerRe: Implementing Strategy Pattern Pin
Pete O'Hanlon16-Jan-17 22:46
mvePete O'Hanlon16-Jan-17 22:46 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi16-Jan-17 23:22
Liagapi16-Jan-17 23:22 
GeneralRe: Implementing Strategy Pattern Pin
harold aptroot16-Jan-17 23:05
harold aptroot16-Jan-17 23:05 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi17-Jan-17 2:25
Liagapi17-Jan-17 2:25 
AnswerRe: Implementing Strategy Pattern Pin
F-ES Sitecore16-Jan-17 23:18
professionalF-ES Sitecore16-Jan-17 23:18 
GeneralRe: Implementing Strategy Pattern Pin
Liagapi16-Jan-17 23:28
Liagapi16-Jan-17 23:28 
GeneralRe: Implementing Strategy Pattern Pin
Bernhard Hiller17-Jan-17 23:21
Bernhard Hiller17-Jan-17 23:21 
AnswerRe: Implementing Strategy Pattern Pin
Gerry Schmitz17-Jan-17 5:48
mveGerry Schmitz17-Jan-17 5:48 
QuestionConvert DateTimeOffset to DateTime in Linq To Entities Pin
Kevin Marois16-Jan-17 13:18
professionalKevin Marois16-Jan-17 13:18 
AnswerRe: Convert DateTimeOffset to DateTime in Linq To Entities Pin
Pete O'Hanlon16-Jan-17 22:52
mvePete O'Hanlon16-Jan-17 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.