By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Return Array from DLL

P: 1
I'm trying to return an array from a DLL.

Expand|Select|Wrap|Line Numbers
  1. extern "C" __declspec (dllexport) BYTE* _stdcall ReturnBytes(void)
  2. {
  3.     BYTE v[5];
  4.     BYTE * p;
  6.     p = v;
  8.     *p++ = 9;
  9.     *p++ = 0;
  10.     *p++ = 2;
  11.     *p++ = 1;
  12.     *p++ = 0;
  14.     return p;
  15. }

How do I get these values when calling the DLL from VB.NET. Can I use the Marshal class to recall the pointer?
Jun 18 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
You can't do this.
BYTE v[5];
BYTE * p;

p = v;
return p;
The array v is a local variable. It get's destroyed when the function completes.

You have to allocate your array on the heap. Then you must remember to delete later. I suggest you use a handle class (smart pointer) for this. There is an article about this in the C/C++ Articles Forum.
Jun 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.