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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:32:53+00:00 2026-06-06T05:32:53+00:00

In a dll, I’m doing std::vector<foo*>* v = new std::vector<foo*>(); foo* f = new

  • 0

In a dll, I’m doing

std::vector<foo*>* v = new std::vector<foo*>();
foo* f = new foo();
v->push_back(f);
// size of v is 1
process->Result = static_cast<void*>(v);  // Result is of type void*

and in a exe that uses the dll, I do

if (process->Result != NULL)
{
   std::vector<foo*>* v = static_cast<std::vector<foo*>*>(process->Result);
   int size = v->size(); // <-- size is garbage (221232 or something like that)   

}

Result has to be a void*. Does anyone know why I’m not able to pass back the vector properly ? Am I doing something wrong with the casting?

Thanks

  • 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-06T05:32:54+00:00Added an answer on June 6, 2026 at 5:32 am

    Because the standard library data structures such as std::vector are implemented in header files, the actual data representation can be different between versions of the compiler. If you have some code compiled with VS2005 and other code with VS2010, you cannot reliably return a std::vector in this way.

    Assuming foo is the exact same data layout between components, you could return an array of raw foo* pointers that has been allocated with HeapAlloc. Do not use malloc() because again, your components are using different runtime libraries and you can’t free() something that has been allocated with a different allocator. By using HeapAlloc and HeapFree, you are using the Win32 standard allocator which is shared across your whole process.

    By way of example, you could do something like:

    v->push_back(f);
    HANDLE heap = GetProcessHeap();
    foo **r = (foo **)HeapAlloc(heap, 0, (v->size() + 1) * sizeof(foo *));
    std::copy(v.begin(), v.end(), r);
    r[v->size()] = NULL; // add a sentinel so you know where the end of the array is
    process->Result = r;
    

    and then in your calling module:

    foo **v = static_cast<foo**>(process->Result);
    for (int i = 0; v[i] != NULL; i++) {
        printf("index %d value %p\n", i, v[i]);
    }
    HANDLE heap = GetProcessHeap();
    HeapFree(heap, 0, v);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

// dll #include <memory> __declspec(dllexport) std::auto_ptr<int> get(); __declspec(dllexport) std::auto_ptr<int> get() { return std::auto_ptr<int>(new int());
My DLL might send more than one result/return value to exe in one shoot.
dll export header extern C void _declspec(dllexport) __stdcall foo(); .def file EXPORTS foo @1
DLL registration with regsvr32.exe freezes when unit HtmlHelpViewer is used in DLL sources in
I have a DLL which exports a function: __declspec(dllexport) void __stdcall MyEntryPoint(char* params) {
I have a dll and an exe both created in my machine. I am
I have a dll(written in vb6) that compiles VB6 code. I'm reading the VB6.exe
С# COM DLL Interface: public interface IShowDialog { void showMessage(byte[] array); } and call
I use a C++ DLL in my app. type Tcl_bla = function(filename: PChar): Integer;
I'm injecting a DLL into another process and want to call a function that

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.