Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
28d29300
Commit
28d29300
authored
Mar 03, 2008
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
user32: Reimplement LoadStringA to avoid memory allocations and to pass the tests.
parent
4b130aa0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
23 deletions
+20
-23
resource.c
dlls/user32/resource.c
+18
-18
resource.c
dlls/user32/tests/resource.c
+2
-5
No files found.
dlls/user32/resource.c
View file @
28d29300
...
...
@@ -24,6 +24,7 @@
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winternl.h"
#include "winnls.h"
#include "wine/winbase16.h"
#include "wine/winuser16.h"
...
...
@@ -400,32 +401,31 @@ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
/**********************************************************************
* LoadStringA (USER32.@)
*/
INT
WINAPI
LoadStringA
(
HINSTANCE
instance
,
UINT
resource_id
,
LPSTR
buffer
,
INT
buflen
)
INT
WINAPI
LoadStringA
(
HINSTANCE
instance
,
UINT
resource_id
,
LPSTR
buffer
,
INT
buflen
)
{
INT
retval
;
LPWSTR
wbuf
;
HGLOBAL
hmem
;
HRSRC
hrsrc
;
DWORD
retval
=
0
;
TRACE
(
"instance = %p, id = %04x, buffer = %p, length = %d
\n
"
,
instance
,
resource_id
,
buffer
,
buflen
);
if
(
buffer
==
NULL
)
/* asked size of string */
return
LoadStringW
(
instance
,
resource_id
,
NULL
,
0
);
if
(
!
buflen
)
return
-
1
;
wbuf
=
HeapAlloc
(
GetProcessHeap
(),
0
,
buflen
*
sizeof
(
WCHAR
));
if
(
!
wbuf
)
return
0
;
retval
=
LoadStringW
(
instance
,
resource_id
,
wbuf
,
buflen
);
if
(
retval
!=
0
)
/* Use loword (incremented by 1) as resourceid */
if
((
hrsrc
=
FindResourceW
(
instance
,
MAKEINTRESOURCEW
((
LOWORD
(
resource_id
)
>>
4
)
+
1
),
(
LPWSTR
)
RT_STRING
))
&&
(
hmem
=
LoadResource
(
instance
,
hrsrc
)))
{
retval
=
WideCharToMultiByte
(
CP_ACP
,
0
,
wbuf
,
retval
,
buffer
,
buflen
-
1
,
NULL
,
NULL
);
buffer
[
retval
]
=
0
;
TRACE
(
"%s loaded !
\n
"
,
debugstr_a
(
buffer
));
}
else
buffer
[
0
]
=
0
;
/* no check of buflen here */
HeapFree
(
GetProcessHeap
(),
0
,
wbuf
);
const
WCHAR
*
p
=
LockResource
(
hmem
);
unsigned
int
id
=
resource_id
&
0x000f
;
while
(
id
--
)
p
+=
*
p
+
1
;
RtlUnicodeToMultiByteN
(
buffer
,
buflen
-
1
,
&
retval
,
p
+
1
,
*
p
*
sizeof
(
WCHAR
)
);
}
buffer
[
retval
]
=
0
;
TRACE
(
"returning %s
\n
"
,
debugstr_a
(
buffer
));
return
retval
;
}
...
...
dlls/user32/tests/resource.c
View file @
28d29300
...
...
@@ -120,11 +120,8 @@ static void test_LoadStringA (void)
"LoadString failed: ret %d err %d
\n
"
,
ret
,
GetLastError
());
ret
=
LoadStringA
(
hInst
,
0
,
buf
,
0
);
todo_wine
{
ok
(
ret
==
-
1
,
"LoadStringA did not return -1 when called with buflen = 0, got %d, err %d
\n
"
,
ret
,
GetLastError
());
}
ok
(
ret
==
-
1
,
"LoadStringA did not return -1 when called with buflen = 0, got %d, err %d
\n
"
,
ret
,
GetLastError
());
}
static
void
test_accel1
(
void
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment