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

  • Home
  • SEARCH
  • 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 7807587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:53:49+00:00 2026-06-02T02:53:49+00:00

everyone… I’ve just started to learn how to create process and thread using Windows

  • 0

everyone… I’ve just started to learn how to create process and thread using Windows API. My code does work if I want thread to display integer on the screen but it doesn’t work when using array of chars… Can someone tell me what am I doing wrong? The code:

#include<stdio.h>
#include<Windows.h>
#include<conio.h>
#include<tchar.h>
#include<strsafe.h>
#include<string.h>

#define N 4
#define bufferSize 255

DWORD WINAPI Threader(LPVOID Parameter);

typedef struct Data {
    char value[bufferSize];
} Data, *pToData;

int main()
{
    int i;
    char c[bufferSize];
    pToData threadData[N];
    HANDLE handleArray[N];
    DWORD threadID[N];

    FILE *file=fopen("niti.txt", "r");

    for(i=0; i<N; i++)
    {
        fscanf(file, "%s", c);
        threadData[i] = (pToData) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Data));
        strcpy(threadData[i]->value, c);
        handleArray[i]=CreateThread(NULL, 0, Threader, threadData[i], 0, &threadID[i]);
    }

    WaitForMultipleObjects(N, handleArray, TRUE, INFINITE);

    for(i=0; i<N; i++)
    {
        CloseHandle(handleArray[i]);
        if(threadData[i] != NULL)
        {
            HeapFree(GetProcessHeap(), 0, threadData[i]);
            threadData[i] = NULL;
        }
    }

    fclose(file);

    return 0;
}

DWORD WINAPI Threader(LPVOID Parameter)
{
    HANDLE hStdOut;
    TCHAR messageBuffer[bufferSize];
    size_t cchStringSize;
    DWORD dwChars;
    pToData dataArray;
    char temp[bufferSize];

    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if( hStdOut == INVALID_HANDLE_VALUE )
        return 1;

    dataArray=(pToData)Parameter;

    StringCchPrintf(messageBuffer, bufferSize, TEXT("Parameter = %s\n"), dataArray->value); 
    StringCchLength(messageBuffer, bufferSize, &cchStringSize);
    WriteConsole(hStdOut, messageBuffer, (DWORD)cchStringSize, &dwChars, NULL);

    return 0;
}

If I change value in my struct to int and do the same in main the output is correct. Any suggestions?
Thank you!

  • 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-06-02T02:53:51+00:00Added an answer on June 2, 2026 at 2:53 am

    You are probably compiling for Unicode but outputting a char array. Your symptoms sound like an encoding mismatch and Unicode output function mis-matched against ANSI char array is the mismatch that results in lots of questions marks.

    In other words I hypothesise that your code resolves StringCchPrintf as StringCchPrintfW. And you then fail to satisfy the contract by passing char* rather than wchar_t* when you pass dataArray->value.

    Use wchar_t or TCHAR instead of char for dataArray->value. Or call the A version of the output functions. Or compile for ANSI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

everyone. I used openjdk-7 on arch linux. I started to learn Java recently, and
everyone.I wanna include javascript in the html(webpy templates),but it doesn't work.the javascript code in
everyone, I have problems when using MVC3 code is as follows public SystemController(IRepository repository)
everyone. I'm having a memory allocation error using ctypes and a C code. I'm
Everyone I work with is obsessed with the data-centric approach to enterprise development and
Everyone managing open-source-software runs into the problem, that with the time the process of
Everyone uses source-code control to manage versions (right?) and this provides some level of
everyone: I am also open to just straight-up refactoring what I'm finding to be
Everyone likes to talk about reusability. Where I work, whenever some new idea is
everyone, I've started working yesterday on the Euler Project in Clojure and I have

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.