473,785 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to transfer a DWORD from a function?

how to would you transfer a DWORD variable from inside of a function to
the caller
ex.
InvokeProcessDa ta(LPDWORD prtDW)
{
...
// we have created, initialized and processed
// dword variable from
DWORD data[32];

// we need to transfer DWORD data to caller
}
so that, the calling function would look like:

winmain(...)
{

DWORD new_data_buffer ;
InvokeProcessDa ta(&new_data_bu ffer);

//later 'new_data_buffe r' will be used for example:

WriteFile(hFile , &new_data_buffe r, ...,)

}

Dec 12 '05 #1
7 3634
monkeydragon wrote:
how to would you transfer a DWORD variable from inside of a function to
the caller
ex.
InvokeProcessDa ta(LPDWORD prtDW)
{
..
// we have created, initialized and processed
// dword variable from
DWORD data[32];

// we need to transfer DWORD data to caller
}
so that, the calling function would look like:

winmain(...)
{

DWORD new_data_buffer ;
InvokeProcessDa ta(&new_data_bu ffer);

//later 'new_data_buffe r' will be used for example:

WriteFile(hFile , &new_data_buffe r, ...,)

}

You can't return an array in C, so you have to use a pointer. Then
there are several ways.

You can make the function fill an array defined outside it directly.
Just define DWORD new_data_buffer[32], and call
InvokeProcessDa ta(new_data_buf fer). Then use prtDW inside the function,
instead of 'data'.

You can also have a static array inside of InvokeProcessDa ta and just
return a pointer to it:

LPDWORD InvokeProcessDa ta(void)
{
static DWORD data[32];
/* fill data with data */

/* this returns a pointer, NOT a copy of the array */
return data;
}
Everytime you call InvokeProcessDa ta it will then overwrite the array,
so you need to copy it if you want to keep the previous version for use
outside the function. But you'd probably want the first method instead
of this.

I'm assuming that LPDWORD is just a DWORD *. And DWORD might be 32 bit
integer, not that it matters.

And you might want to use

#define PROCESS_DATA_SI ZE 32

or something like that, instead of using the number directly. It
documents what the number is for, makes it easier to change it since you
only need to change it in one spot, and also makes it unlikely that you
type 23 somewhere instead of 32, etc.
Dec 12 '05 #2
int foo (LPDWORD prtDW, LPDWORD& prtResultDW)
{
// .....
// Create required size array and store pointer to it in external
// variavle, and size of it can be returned as a result of
function.
int res_size = XX;
prtResultDW = new DWORD[res_size];

/// ....

return res_size;
}

or

void foo (LPDWORD prtDW, LPDWORD prtResultDW)
{
// .....
// prtResultDW = pointer to array where is enough space for store
results
// ....
}

Dec 12 '05 #3
"monkeydrag on" <ke***********@ gmail.com> wrote:
how to would you transfer a DWORD variable from inside of a function to
the caller
ex.
InvokeProcessDa ta(LPDWORD prtDW)
{
..
// we have created, initialized and processed
// dword variable from
DWORD data[32];

// we need to transfer DWORD data to caller
}
so that, the calling function would look like:

winmain(...)
{

DWORD new_data_buffer ;
InvokeProcessDa ta(&new_data_bu ffer);

//later 'new_data_buffe r' will be used for example:

WriteFile(hFile , &new_data_buffe r, ...,)

}


You passed a pointer to InvokeProcessDa ta; so why
not just write to that location in that function,
like so:

(*prtDW) = 72;

That will write 72 to your local variable in Winmain().

If you need to pass more data than just one DWORD
back to Winmain, then make an array in Winmain()
and pass it to InvokeProcessDa ta():

// In Winmain():
DWORD BigArray[500];
InvokeProcessDa ta(BigArray)

// In InvokeProcessDa ta():
InvokeProcessDa ta(DWORD* Blat)
{
for (int i=0; i<500; ++i)
{
Blat[i] = whatever // writes to BigArray in Winmain()
}
}

Or better, pass a std::list by non-const ref:

// In Winmain():
....
std::list<DWORD > MyList;
....
InvokeProcessDa ta(MyList);
....

// In InvokeProcessDa ta():
void InvokeProcessDa ta(std::list<DW ORD> & Blat)
{
...
std::list<DWORD >::iterator
for (i=Blat.begin() ; i!=Blat.end; ++i)
{
(*i) = whatever // writes to MyList in Winmain()
}
...
}

--
Robbie Hatley
Tustin, CA, USA
lone wolf intj at pac bell dot net
home dot pac bell dot net slant earnur slant
Dec 12 '05 #4
i did something like this:
InvokeProcessDa ta(UINT selOffset, LPDWORD pData)
{
DWORD byteStorage[32];
// initializations and other things...
// then...
*pData = byteStorage[selOffset];
}

what do you think?

Dec 12 '05 #5
If I understand You correctly, You try return from function array of
DWORD values, or not, and You need return only one ? If you want return
only one You can use return operator.

Dec 13 '05 #6
Geo

monkeydragon wrote:
i did something like this:
InvokeProcessDa ta(UINT selOffset, LPDWORD pData)
{
DWORD byteStorage[32];
// initializations and other things...
// then...
*pData = byteStorage[selOffset];
}

what do you think?


I think, no I know, you don't want to do that (assuming LPDWORD is a
DWORD*).

Outside of InvokeProcessDa ta, byteStorage doesn't exist, so pData will
be a pointer into unallocated memory, very bad.

Dec 13 '05 #7
I am sorry to cause you much trouble, but i have already resolved that
problem.
I use CopyMemory();
Thank anyways,

_May_the_force_ be_with_you_

Dec 14 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
8091
by: Xanax | last post by:
Hi all, I have an edit box in my app displaying the results of function executions as strings. But some of the functions return the result of driver properties, which are in DWORD format. Is there a way to oncert DWORD to String so it will display in the edit box? Cheers. Kevin.
7
4356
by: __PPS__ | last post by:
Actually what I mean is that - if I have some memory buffer, lets say char a; and then I do like this: DWORD num = 0x1234; *(DWORD*)a = num; (1) *(DWORD*)(a+1) = num; (2) either (1) or (2) will assign dword value to not dword aligned address. The question is - will this code be fatal on some systems??
16
16429
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
7
4147
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid. Also trying to avoid setting it to a bigint in the server. Casting an int to an uint use to work in C++. System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(...); cn.Open()
2
1794
by: Vladimir_petter | last post by:
Hello All, I've fount that if I compile the same program using gcc and vc 2003 the same class E (see complete source bellow) has different size (on vc it is 4 bytes bigger). Digging into this I've found that vc is reserving a dword in the E class right before storage for virtual base class. In my tests value of this dword always was 0. I did not see any code referencing this memory. Anybody has any idea what this dword is for? ...
1
4702
by: Gabest | last post by:
Running this piece of code while having the sse optimization turned on (vcnet2003), something really strange happens I cannot explain. Without sse it is giving me the right results. float f = 0.8; f *= UINT_MAX; DWORD dw = (DWORD)f; Basically the result in dw should be 0xcccccccc (or 0xcccccd00 because of float's inaccuracy), but instead I get 0x80000000 for anything above f =
6
16816
by: CMG | last post by:
I am writing a little code to associate an extention with my program. And as far as i can see, i need to do the following: Public Function associatefile(ByVal FILE_EXTENTION_TO_ASSOCIATE As String, ByVal FILE_EXTENTION_DESCRIPTION As String, ByVal EXE_NAME As String, ByVal DEFAULT_OPEN_COMMAND As String, ByVal DEFAULT_ICON As String, ByVal ACTION_NAME As String) Dim RegKey As RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey
4
13025
by: Virajitha Sarma | last post by:
Hi, I have a code in C which i am rewritting it in C#. I am facing problem with the following two lines : char *cipher; (DWORD*)cipher(C) and (uint*)cipher(C#) are giving different values though both DWORD(which is unsigned long) and uint occupy 4 bytes Why is it happening ? Any insight into this topic would be highly
6
12655
by: ppuniversal | last post by:
I am facing a problem: I have say 3 files : ABC.h ----- this file has the function prototypes ABC.cpp ------ the definitions of the functions ABC_Test.cpp ------- the file with main() which calls the functions using ABC's object say "ob". Now I want to make a function say "startNewThread()" inside ABC.cpp and its prototype in ABC.h, then where should I define
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.