|
As others have pointed out, the issue is with pBuffer not associated with any allocated memory.
In addition to this, I would like to point out one more flaw in your code, although it doesn't matter in this case.
The third parameter to SetFilePointer[^] must be an address of a LONG variable.
PLONG does not declare a LONG variable. It's only a pointer to a LONG variable.
Here SetFilePointer will actually try to write to memory 0 .
What you need to do is declare a LONG variable and provide its address -
LONG highValue; SetFilePointer(..., ..., &highValue, ...); You can also pass a nullptr , if you're not intersted in that value.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
It will interest me, not this time, but in the real program. I modified the code like this:
LONG lValueLow = 0;
LONG lValueHigh = 0;
if (INVALID_SET_FILE_POINTER == SetFilePointer(hVolume, lValueLow, &lValueHigh, FILE_BEGIN) &&
NO_ERROR != GetLastError())
{
TRACE("Error: %d\n", GetLastError());
return FALSE;
}
else
{
TRACE("%d\t%d\n", lValueLow, lValueHigh);
}
Thank you Superman !
|
|
|
|
|
You do not need lValueHigh unless the distance to move is a 64 bit value: just specify NULL instead.
Also I suggest you study the difference between a variable and a pointer to a variable, you seem somewhat confused about it.
|
|
|
|
|
Understood now, I didn't paid attention on that function (lpDistanceToMoveHigh , is obviously now, or, at least I think is obviously).
|
|
|
|
|
struct TestStruct
{
int x;
int z;
};
TestStruct S;
TestStruct Funct()
{
return S;
}
Funct().x = 100;
Will this work?
|
|
|
|
|
Yes, but Func() is not really necessary, since you have already declared S . You can just say S.x = 100;
Creating a function to return a structure (or anything else) is usually necessary when you cannot declare the relevant object at compile time, but need to create it dynamically. Something like:
TestStruct* Funct()
{
TestStruct* pS = new TestStruct;
pS->x = 0;
ps->z = 0;
return pS;
}
TestStruct* pNewStruct = Funct();
pNewStruct->x = 100;
|
|
|
|
|
Hello,
the code itself will work, but will not do what I suppose you expect.
Here, Funct returns a copy of the TestStruct S.
So Funct().x = 100 will affect 100 in a temporary TestStruct that you can not use after that.
I don't know why you want to use a function to access your S structure, but the behavior you look for is probably :
TestStruct& Funct()
{
return S;
}
|
|
|
|
|
my actual code:
ChartNode Chart[100];
ChartNode NodeCoord(int x, int z)
{
return Chart[z * 10 + x];
}
if(NodeCoord(4,4).access)
NodeCoord(4,4).access = false;
The result I`m looking for is the same as the result achieved with this function:
void NodeCoord(int x, int z, bool writetobool)
{
Chart[z * 10 + x].access = writetobool;
}
modified 3-May-20 5:10am.
|
|
|
|
|
So you probably need to return a reference :
ChartNode& NodeCoord(int x, int z)
{
return Chart[z * 10 + x];
}
else the NodeCoord(4,4).access = false will assign a temporary copy of your ChartNode struct and not the one in your array.
|
|
|
|
|
ChartNode& NodeCoord() will work for both read and write?
|
|
|
|
|
|
If you are referring to array cells with two dimension values then you should use a two-dimensional array. As it is you can pass any values in to NodeCoord but there is no way of telling if they are valid. So you could end up with lots of random memory corruption.
|
|
|
|
|
Thanks Richard
How do I declare a two (or more) dimensional array? The problem is I might need arrays with a great number of dimensions. I need a `one fits all` type of solution.
modified 3-May-20 5:42am.
|
|
|
|
|
Just like a one-dimensional, but you declare the two dimensions. Think of it as a block of items having some number of rows and columns. so you could have something like:
#define MAXROW 10
#define MAXCOL 5
ChartNode Chart[MAXROW][MAXCOL];
ChartNode NodeCoord(int row, int column)
{
if (row > 0 && row < MAXROW && column > 0 && column < MAXCOL) {
return Chart[row, column]; }
else
{
return NULL; }
}
All of these features are well documented in the C/C++ documentation and the various tutorials on the language.
|
|
|
|
|
the two dimensional array seems like something too good to be true The compiler is definitely doing something suspicious behind the courtain.
Thanks.
modified 3-May-20 6:31am.
|
|
|
|
|
I think you could do with studying all the features of C (or C++ if that is what you are using). Trying to learn a language by posting questions here will take ten times as long, and you will still miss most of it.
|
|
|
|
|
Internally it's just continuous memory that is allocated for a 2 dimensional array (For any no. of dimensions for that matter).
The compiler uses the specified dimensions to calculate the offset into the memory to fetch.
For instance, offset of Chart[2][3] could be calculated as -
(sizeof(ChartNode) * MAXROW * 2) + (sizeof(ChartNode) * 3)
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Often I edit my posts/replies shortly after making them, I can`t organise myself in a single swing.
|
|
|
|
|
I have a shipping piece of software, that uses property sheets for Tools/Options. For almost all my customers everything is perfect, but for just 2 or 3 the property sheets appear as though the dialog units are too large. The fonts, edit boxes, and all controls are about 1/3 too large, but with the same 0,0 origin. Even so, the containing dialog size is unchanged, so the result is that some of the controls on the right and bottom are either clipped or not visible at all.
We only use property sheets in two places, and for customers with this problem, both instances are affected identically. This only happens with Property sheets, and not with normal dialogs.
The resources are defined in the .rc file like:
DLG_PREF7 DIALOG 10, 91, 300, 179
STYLE DS_ABSALIGN | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Font"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Fixed-width font",79,7,7,119,12,SS_CENTERIMAGE
COMBOBOX 80,131,7,126,300,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_GROUP | WS_TABSTOP
LTEXT "Proportional font",87,7,25,119,12,SS_CENTERIMAGE
COMBOBOX 88,131,25,126,300,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_GROUP | WS_TABSTOP
LTEXT "Font size",-1,7,43,119,12,SS_CENTERIMAGE
EDITTEXT 705,131,43,20,12,ES_RIGHT | ES_NUMBER | WS_GROUP | WS_TABSTOP
END
A picture would be worth a thousand words, but I can't post a picture. Imagine if you could have used ctrl/mouse-wheel to increase the size of the contents of just this dialog.
I am stumped. Does anyone have an idea of what might be happening?
|
|
|
|
|
It seems to be a one of the property pages displayed in the property sheet.
How do other pages look like (I mean in the resources)?
|
|
|
|
|
I have run your dialog and tried various changes to see if it affects it but nothing seems to go wrong. It may be worth checking the versions of Windows that the clients are running to see if that is a common factor.
|
|
|
|
|
I am trying to convert a C Linux library to Windows. And I've met something weird. I have a variable:
struct dir_struct
{
void* display;
char directory[DIR_NAME_LEN];
...
....
but when I listed this variable on my debugger:
TRACE("\n=>%s\n", dir_struct->directory);
Result:
=>/Wise Registry Cleaner/Oe©*BºcE«Mòצ£š{@Q—Y|†Š˜b!
k3©‘ø¼/´4þ"Ðõ÷düJ¤$èû8©KªõÝ5ø³/ò|"Áæpç5V—{?*õ;øœÎj¬þ‹.Ý‚Ä/AÆ]Gݨ ïk<br />
‚¥¡C©…º/GÏ/^×ÒÇ\b/`£ç£×9ʼn_9ßÛ8}añˆg–¿§<êZøM[ÈCø`ƒ"ö~J÷L4/Lè¶Î¸G¢Êèojµ¶/–ãÛxÌZÀ##qǸ=//Y⢠¶LÉKºëÈš"Êã!"Ìd#vŽM-Gþ}?<br />
H’ƒÿidÔ’£lÖ#S///Híz<nÉ(BîU’{t0////i&e.ÆF|S.`[íbd6Óôà…ŸÝÂw+{[0//ÈÎû,ðŠ$Èí7ƒr«¨/,"–ZHfã w<br />
f¡
' †SZPÔoärEÁ/@«Ô<br />
³$,©ÀÙ‚ø//í*‚Þ!ÍÙÉ4ÅZw6(bÚxZž†"ŠÊl…¡Ã//Ö¢HÄ£:vÄ,)‰²/UˆÂÔU±´Íüêp//Ÿ°ÖÏe¢ªHÝXaÍ///mÐw1 粪6r*n//r šT3fÞ:cùÇz<br />
/€à1UK_îˆ]Xj//ôÁ½ÓR¦ÍO?)Ë>Ø£á€MÃ=¿U"œ*CÜFeR//ˆ¹5»mŠ€€†Â#øD/×c|ÔÂq,’X`t¸I//TÁ ½w¢u,¸ ß÷ìÔ¶‚Ô„;%ÀÔI¯¤w¡"lïÌC8ñÅÿ/ùꇌmŸ‹àúÚÃÓÍ3ãµ+TG¯@qܾA¬t´+vÛutô|‰Ä~:žÞHÏê6'9B~o½/þŒ#ƒ-©¶Ô"÷³'£//"Ù³{R"DLUDz] œ<br />
1½&{ÙòMÇ–_o™ºEí /ôež…°Û¬"¢ ¿‚yÚÊ£Cýñ:(×N±/’z¹>eV®
Þ¦)ûªÝvlleŽ/xØB¡RÚ_Ò^6y¿w`žs¤‘øÂÂO{;ªqûN/0€È#@–ñyøq½nç
Why I have this garbage ? Because my folder is Wise Registry Cleaner only ... If I would understand it, maybe I can get rid of it ...
|
|
|
|
|
It's showing all that garbage because the character array is obviously not NULL terminated.
You'll have to look at the documentation to see how to know the proper length of the string.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you. I have seek it \0 char in that string, but I didn't found it ...
|
|
|
|
|
There might be some other way that the library determines the length of the string. Is there any documentation?
Otherwise you can try adding this line of code before printing the string:
dir_struct->directory[DIR_NAME_LEN - 1] = 0; <<======================This line of code
TRACE("\n=>%s\n", dir_struct->directory);
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|