PDA

View Full Version : GetComputerName returns only the first character of the hostname in IS 2011



tier-3
09-05-2010, 11:31 PM
My existing project uses the GetComputerName function. After upgrading to IS 2011, only the first character of the hostname is returned.
I also tried the following code on a new project on both IS 2010 and 2011.



prototype BOOL KERNEL32.GetComputerName(BYREF STRING, BYREF NUMBER);

function OnBegin()
STRING szCmpName;
NUMBER nLength;
begin

//Using Win32 API
nLength = MAX_PATH;
GetComputerName(szCmpName, nLength);
MessageBox(szCmpName, INFORMATION);

end;



IS 2010 returns the full hostname.
IS 2011 returns the first character for the hostname.

joshstechnij
09-07-2010, 12:57 PM
The prototype for this API is not specifying which thunk should be used (ANSI or Unicode). Therefore, the engine is defaulting to the Unicode version due to the Unicode changes made for IS 2011. Because the prototype is also using STRING parameters (i.e. ANSI strings), there is an mismatch here between the API and the parameter types. The prototype should be changed to specify which thunk to call (GetComputerNameA for ANSI or GetComputerNameW for Unicode) and the string parameter types should match (STRING for ANSI string parameters, WSTRING for Unicode string parameters).

Please see the "Q208911: Upgrading Projects to InstallShield 2011 (http://kb.flexerasoftware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=Q208911&sliceId=)" article for more information.

tier-3
09-08-2010, 02:08 AM
Thanks for the information. I will make the nescessary changes as suggested.

theafterglow
08-12-2011, 10:33 AM
Thanks, this was a mystery to me also!!!