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 7804081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:47:56+00:00 2026-06-02T01:47:56+00:00

I am writing two applications, a producer and a consumer. My code is nearly

  • 0

I am writing two applications, a producer and a consumer. My code is nearly identical to the MSDN example thus far :

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551%28v=vs.85%29.aspx

I have set up an event in the Producer which correctly triggers a response in the consumer. The producer creates a value in shared memory, and the consumer correctly responds, then opens the value and prints it via MessageBox.

However i am trying to get the producer to store a LARGE_INT rather than a tchar array. When i try to change CopyMemory to use a long instead, i get errors.

CopyMemory((PVOID)pBuf, timeStart, sizeof(long));

Any ideas on how i can modify it (again my code is near identical to the MSDN example) to store and retrieve a LARGE_INT?

  • 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-02T01:47:57+00:00Added an answer on June 2, 2026 at 1:47 am

    You’re passing the value of timeStart, but you need to pass its address:

    CopyMemory((PVOID)pBuf, (void *)&timeStart, sizeof(timeStart));
    

    Edit: I should add, however, that I think this is generally the wrong way to go. With CopyMemory, you’re basically turning everything into raw bits, which you then have to reconstitute into real data as it comes out the other end.

    Instead of that, I’d generally prefer to do something like:

    void *shared_base = whatever; // base address of shared memory segment
    
    struct shared_data { 
        // The types of the data you actually need to share go here...
        LARGE_INTEGER x;
        int y;
        char z[512];
    };
    
    shared_data *data = (shared_data *)shared_base;
    

    That much is basically the same on both sides. Then, on the producer side, you’d do something like:

    data->x = my_large_integer;
    SetEvent(data_ready);
    

    …and on the consumer side, something like:

    LARGE_INTEGER foo = data->x;
    ResetEvent(data_ready);
    

    This basically lets you do casting in one place, and then use the members of the structure directly, instead of having casts everywhere you need to access the shared data. Of course, you can get much more elaborate with it as well — for example, if you want to be able to use (most of) the shared block for more than one purpose, you might use a union instead of a struct (or you might have a struct containing a union, etc., just like with any other code).

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

Sidebar

Related Questions

I am writing the code for a server that would help two different applications
Which of these two platforms/ecosystems are better for writing web applications/websites? I am not
Just putting part of some code here where I am writing two values to
I am writing code that will spawn two thread and then wait for them
Suppose that I am writing two applications for my employer, we'll call them App1
I'm writing an application that has a multiple producer, single consumer model (multiple threads
I am writing two console applications, a client and a server. I'm a little
I'm writing two applications (in C), which make several calls to send and receive
I'm writing two Django applications: one that generates a lot of data in time,
I am writing two applications: one to write data to a file and another

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.