Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6373667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:23:27+00:00 2026-05-25T01:23:27+00:00

So I have a C++ application that takes a value from a key in

  • 0

So I have a C++ application that takes a value from a key in a settings.INI file, uses libcurl to reach out to a PHP page, post that data, and it should return some different data.

And it actually works, aside from grabbing the data from the INI file. If I explicitely type in for the POSTFIELDS option for libcurl (e.i.: “Serial=454534” , instead of the variable storing the data that it retrived from my file).

Here’s some code..
PHP:

<?
include("DBHeader.inc.php");
$Serial= $_POST['Serial'];

$sql = "SELECT * FROM `LockCodes` WHERE `sLockCode`=\"$Serial\"";
$RS=mysql_query($sql, $SQLConn);
$num_rows=mysql_num_rows($RS);

if ($num_rows>0)
{
      while ($row = mysql_fetch_array($RS))
  {
       echo $row['iLockCodeID'];
  }
}
else
{
  echo "...";
}


?>

Snippet of C++ code:

TCHAR szKeyValue[36];
GetPrivateProfileString(_T("Test"), _T("LockCode"), _T(""), szKeyValue, 36, _T("C:\\Test\\Settings.INI"));

CString sLockCode = szKeyValue;
CURL *curl;
CURLcode res;
CString Serial = _T("Serial=") + sLockCode;
string LCID;

curl_global_init(CURL_GLOBAL_ALL);

curl = curl_easy_init();
if (curl)
{
    curl_easy_setopt(curl, CURLOPT_URL, "http://regserver2.nyksys.com/GetLCID.php");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Serial);
    res = curl_easy_perform(curl);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    res = curl_easy_perform(curl);

    if (data == _T("..."))
    {
        data = "0";
        AfxMessageBox("Invalid Serial Number");
        exit(0);
    }

My Settings.INI is in the standard format..

[Test]
LockCode=1D4553C7E7228E462DBAAE267977B7CDED8A

What happens is whenever I use the variable “Serial” instead of typing it in, the PHP page returns “…” instead of the desired result.

I feel like I’m missing something obvious. Any help would be TREMENDOUSLY appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:23:28+00:00Added an answer on May 25, 2026 at 1:23 am

    I am guessing that you have _UNICODE defined, which means that TCHAR is wchar_t, CString is CStringT<wchar_t>, and the code:

    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Serial);
    

    actually passes a wide char string to curl_easy_setopt() when the function is expecting a narrow char string. If your machine is little Endian, then curl_easy_setopt() interprets the parameter as the string "S\x00e\x00r\x00i\x00... (on a Big Endian machine, it’s "\x00S\x00e\x00r\x00i...) and because curl_easy_setopt() will use strlen() when CURLOPT_POSTFIELDSIZE is not set, the entire POST request body on a little Endian machine is S. See, for example, http://codepad.org/JE2MYZfU

    What you need to do is use narrow char strings:

    #define ARRAY_LEN(arr_id) ((sizeof (arr_id))/(sizeof ((arr_id)[0])))
    
    char szKeyValue[36];
    GetPrivateProfileStringA("Test", "LockCode", "", szKeyValue, ARRAY_LEN(szKeyValue), "C:\\Test\\Settings.INI");
    
    CURL *curl;
    CURLcode res;
    CStringT<char> Body = CStringT<char>("Serial=") + szKeyValue;
    string LCID;
    
    curl_global_init(CURL_GLOBAL_ALL);
    
    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "http://regserver2.nyksys.com/GetLCID.php");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, Body);
        res = curl_easy_perform(curl);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        res = curl_easy_perform(curl);
    //...
    

    Also, your PHP script looks vulnerable to SQL injection.

    EDIT: One more thing. Are you setting CURLOPT_POST to 1?

        curl_easy_setopt(curl, CURLOPT_POST, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that needs to take a file upload from the
Currently I have an application that takes information from a SQLite database and puts
I have an application that takes the quality results for a manufacturing process and
I have an application with a REST style interface that takes XML documents via
I have a Java application that's very String-heavy - it takes a feed of
I have an application that reads a CSV file with piles of data rows.
I have an application that uses NHibernate as its ORM and sometimes it experiences
I have a Web Application that I'm trying to move from Sun Application Server
I have a very weird problem. I have a VB.NET 2.0 application that takes
We have an asp.net webpage that uses viewstate. During a lengthy operation (that takes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.