vendredi 29 janvier 2016

Conversion from String to char* C++ function

Here is my code :

Excella.h

class Excella
{
public:
    string ScannerCheque(string DeviceName, char* settings, char* docInfo, DWORD docInfoBufferSize);
};

Excella.cpp

string Excella::ScannerCheque(string DeviceName, char * settings, char* docInfo, DWORD docInfoBufferSize)
{
    DWORD dwStatus;
    dwStatus = MTMICRProcessCheck((char*) DeviceName.c_str(), settings, docInfo, &docInfoBufferSize);

    //checking if the process went well
    if (dwStatus == MICR_ST_OK) {
        string docInfoString(docInfo);
        return docInfoString;
    }
    else 
        return "";
}

The result I get from MTMICRProcessCheck is stored in the argument docInfo.

main.cpp

DWORD dwStatusS;
DWORD SettingsBufferSize;
SettingsBufferSize = 4096;
DWORD docInfoBufferSize;
docInfoBufferSize = 4096;
string scanner;
char docInfo[4096] = "";
char Settings[4096] = "";

//devices is a combobox
String^ dev = devices->Text->ToString();

if (dev != "") {
    MessageBox::Show(dev);
    IntPtr p = Marshal::StringToHGlobalAnsi(dev);
    string DeviceName;
    DeviceName = static_cast<char*>(p.ToPointer());
    Marshal::FreeHGlobal(p);
    scanner = excella.ScannerCheque(DeviceName, Settings,docInfo,docInfoBufferSize);
}
else MessageBox::Show("Device s name is null");

The problem is that the function "MTMICRProcessCheck" in excella.cpp file returns 'Bad parameter' so clearly, there is a problem with the variable DeviceName..maybe when i tried to do the convertion from System::String to std::string something went wrong! thank u for ur help!

Aucun commentaire:

Enregistrer un commentaire