[in, out] variables - best not to reuse them! [moved]
-
spent a while wondering why szProp2 was returning a truncated string...D'oh! :-O
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize=256; MsiGetProperty(hMsi, "Property1", szProp1, &dwSize); MsiGetProperty(hMsi, "Property2", szProp2, &dwSize);
(the last argument of MsiGetProperty takes the size of the buffer szProp1 as input, and returns the number of characters copied into szProp1 as output;P) -- moved at 8:08 Monday 16th April, 2007 -
spent a while wondering why szProp2 was returning a truncated string...D'oh! :-O
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize=256; MsiGetProperty(hMsi, "Property1", szProp1, &dwSize); MsiGetProperty(hMsi, "Property2", szProp2, &dwSize);
(the last argument of MsiGetProperty takes the size of the buffer szProp1 as input, and returns the number of characters copied into szProp1 as output;P) -- moved at 8:08 Monday 16th April, 2007 -
True, even if it is more on the side of code-error than of code-horror one. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
:laugh:true, but this would fit perfectly in this forum if it was still called 'hall of shame' ;P....
-
spent a while wondering why szProp2 was returning a truncated string...D'oh! :-O
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize=256; MsiGetProperty(hMsi, "Property1", szProp1, &dwSize); MsiGetProperty(hMsi, "Property2", szProp2, &dwSize);
(the last argument of MsiGetProperty takes the size of the buffer szProp1 as input, and returns the number of characters copied into szProp1 as output;P) -- moved at 8:08 Monday 16th April, 2007 -
:laugh:true, but this would fit perfectly in this forum if it was still called 'hall of shame' ;P....
Well, it would fit in "Subtle bugs" forum nicely. But it is kinda WTF from design on API. It just begs to be (mis)used this way.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
-
spent a while wondering why szProp2 was returning a truncated string...D'oh! :-O
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize=256; MsiGetProperty(hMsi, "Property1", szProp1, &dwSize); MsiGetProperty(hMsi, "Property2", szProp2, &dwSize);
(the last argument of MsiGetProperty takes the size of the buffer szProp1 as input, and returns the number of characters copied into szProp1 as output;P) -- moved at 8:08 Monday 16th April, 2007I can honestly say I have never seen that one before; which is saying a lot. :laugh:
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
spent a while wondering why szProp2 was returning a truncated string...D'oh! :-O
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize=256; MsiGetProperty(hMsi, "Property1", szProp1, &dwSize); MsiGetProperty(hMsi, "Property2", szProp2, &dwSize);
(the last argument of MsiGetProperty takes the size of the buffer szProp1 as input, and returns the number of characters copied into szProp1 as output;P) -- moved at 8:08 Monday 16th April, 2007Use C's "delayed assignement" :
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSize=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&(dwSize=256)**);
or even :TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSizeProp1; DWORD dwSizeProp2; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSizeProp1=dwSizeProp2=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&dwSizeProp2**);
It looks weird at first, but it works and avoid several bugs of this kind ! KochiseIn Code we trust !
-
Use C's "delayed assignement" :
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSize=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&(dwSize=256)**);
or even :TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSizeProp1; DWORD dwSizeProp2; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSizeProp1=dwSizeProp2=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&dwSizeProp2**);
It looks weird at first, but it works and avoid several bugs of this kind ! KochiseIn Code we trust !
Kochise wrote:
MsiGetProperty(hMsi, "Property1", szProp1, &(dwSize=256)); MsiGetProperty(hMsi, "Property2", szProp2, &(dwSize=256));
good idea...code is much nicer to look at :)
-
Kochise wrote:
MsiGetProperty(hMsi, "Property1", szProp1, &(dwSize=256)); MsiGetProperty(hMsi, "Property2", szProp2, &(dwSize=256));
good idea...code is much nicer to look at :)
:cool: I have never seen or thought of that before. I do not recommend it though, because the next, less experienced, C programmer that comes along will be saying WTF. :doh: I admit that I like the way it looks and consider it very creative. So I am very glad Kochise posted it. :-D
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Use C's "delayed assignement" :
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSize=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&(dwSize=256)**);
or even :TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSizeProp1; DWORD dwSizeProp2; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSizeProp1=dwSizeProp2=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&dwSizeProp2**);
It looks weird at first, but it works and avoid several bugs of this kind ! KochiseIn Code we trust !
>. MsiGetProperty(hMsi, "Property1", szProp1, &(dwSize=256)); Wow! Never seen that one before. Thanks
-
:cool: I have never seen or thought of that before. I do not recommend it though, because the next, less experienced, C programmer that comes along will be saying WTF. :doh: I admit that I like the way it looks and consider it very creative. So I am very glad Kochise posted it. :-D
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Use C's "delayed assignement" :
TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSize; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSize=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&(dwSize=256)**);
or even :TCHAR szProp1[256]; TCHAR szProp2[256]; DWORD dwSizeProp1; DWORD dwSizeProp2; MsiGetProperty(hMsi, "Property1", szProp1, **&(dwSizeProp1=dwSizeProp2=256)**); MsiGetProperty(hMsi, "Property2", szProp2, **&dwSizeProp2**);
It looks weird at first, but it works and avoid several bugs of this kind ! KochiseIn Code we trust !
The beauty of C++ - there's always a nasty looking trick that one day will save your backus.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!|FoldWithUs! | sighist