Changed LPCWSTR to LPWSTR in the Windows code as the C means const and there are a few cases of const->non-const conversions as a result.

This commit is contained in:
Pietro Gagliardi 2014-08-01 18:25:59 -04:00
parent 7f027bae3c
commit 80828b8a7d
10 changed files with 23 additions and 24 deletions

View File

@ -3,7 +3,7 @@
#include "winapi_windows.h" #include "winapi_windows.h"
#include "_cgo_export.h" #include "_cgo_export.h"
HWND newWidget(LPCWSTR class, DWORD style, DWORD extstyle) HWND newWidget(LPWSTR class, DWORD style, DWORD extstyle)
{ {
HWND hwnd; HWND hwnd;

View File

@ -16,7 +16,7 @@ LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
ICC_LISTVIEW_CLASSES | /* list views */ \ ICC_LISTVIEW_CLASSES | /* list views */ \
0) 0)
DWORD initCommonControls(LPCWSTR manifest, char **errmsg) DWORD initCommonControls(LPWSTR manifest, char **errmsg)
{ {
ACTCTX actctx; ACTCTX actctx;
HANDLE ac; HANDLE ac;

View File

@ -39,7 +39,7 @@ func initCommonControls() (err error) {
var errmsg *C.char var errmsg *C.char
errcode := C.initCommonControls(C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(filename))), &errmsg) errcode := C.initCommonControls(C.LPWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(filename))), &errmsg)
if errcode != 0 || errmsg != nil { if errcode != 0 || errmsg != nil {
return fmt.Errorf("error actually initializing comctl32.dll: %s: %v", C.GoString(errmsg), syscall.Errno(errcode)) return fmt.Errorf("error actually initializing comctl32.dll: %s: %v", C.GoString(errmsg), syscall.Errno(errcode))
} }

View File

@ -8,14 +8,14 @@ LRESULT getWindowTextLen(HWND hwnd)
return SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0); return SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
} }
void getWindowText(HWND hwnd, WPARAM n, LPCWSTR buf) void getWindowText(HWND hwnd, WPARAM n, LPWSTR buf)
{ {
SetLastError(0); SetLastError(0);
if (SendMessageW(hwnd, WM_GETTEXT, n + 1, (LPARAM) buf) != n) if (SendMessageW(hwnd, WM_GETTEXT, n + 1, (LPARAM) buf) != n)
xpanic("WM_GETTEXT did not copy the correct number of characters out", GetLastError()); xpanic("WM_GETTEXT did not copy the correct number of characters out", GetLastError());
} }
void setWindowText(HWND hwnd, LPCWSTR text) void setWindowText(HWND hwnd, LPWSTR text)
{ {
switch (SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM) text)) { switch (SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM) text)) {
case FALSE: case FALSE:

View File

@ -21,8 +21,8 @@ func xmissedmsg(purpose *C.char, f *C.char, uMsg C.UINT) {
panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f))) panic(fmt.Errorf("%s window procedure message %d does not return a value (bug in %s)", C.GoString(purpose), uMsg, C.GoString(f)))
} }
func toUTF16(s string) C.LPCWSTR { func toUTF16(s string) C.LPWSTR {
return C.LPCWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(s))) return C.LPWSTR(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
} }
func getWindowText(hwnd C.HWND) string { func getWindowText(hwnd C.HWND) string {
@ -31,6 +31,6 @@ func getWindowText(hwnd C.HWND) string {
n := C.getWindowTextLen(hwnd) n := C.getWindowTextLen(hwnd)
buf := make([]uint16, int(n + 1)) buf := make([]uint16, int(n + 1))
C.getWindowText(hwnd, C.WPARAM(n), C.getWindowText(hwnd, C.WPARAM(n),
C.LPCWSTR(unsafe.Pointer(&buf[0]))) C.LPWSTR(unsafe.Pointer(&buf[0])))
return syscall.UTF16ToString(buf) return syscall.UTF16ToString(buf)
} }

View File

@ -4,7 +4,7 @@
#include "_cgo_export.h" #include "_cgo_export.h"
/* provided for cgo's benefit */ /* provided for cgo's benefit */
LPCWSTR xWC_TABCONTROL = WC_TABCONTROL; LPWSTR xWC_TABCONTROL = WC_TABCONTROL;
static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data) static LRESULT CALLBACK tabSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
{ {
@ -42,14 +42,13 @@ void setTabSubclass(HWND hwnd, void *data)
xpanic("error subclassing Tab to give it its own event handler", GetLastError()); xpanic("error subclassing Tab to give it its own event handler", GetLastError());
} }
void tabAppend(HWND hwnd, LPCWSTR name) void tabAppend(HWND hwnd, LPWSTR name)
{ {
TCITEM item; TCITEM item;
LRESULT n; LRESULT n;
ZeroMemory(&item, sizeof (TCITEM)); ZeroMemory(&item, sizeof (TCITEM));
item.mask = TCIF_TEXT; item.mask = TCIF_TEXT;
/* TODO the C means const; change everything to use LPWSTR instead */
item.pszText = name; item.pszText = name;
/* MSDN's example code uses the first invalid index directly for this */ /* MSDN's example code uses the first invalid index directly for this */
n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0); n = SendMessageW(hwnd, TCM_GETITEMCOUNT, 0, 0);

View File

@ -15,7 +15,7 @@ type controlParent struct {
hwnd C.HWND hwnd C.HWND
} }
func newControl(class C.LPCWSTR, style C.DWORD, extstyle C.DWORD) *controlbase { func newControl(class C.LPWSTR, style C.DWORD, extstyle C.DWORD) *controlbase {
c := new(controlbase) c := new(controlbase)
c.hwnd = C.newWidget(class, style, extstyle) c.hwnd = C.newWidget(class, style, extstyle)
c.controldefs = new(controldefs) c.controldefs = new(controldefs)

View File

@ -4,7 +4,7 @@
#include "_cgo_export.h" #include "_cgo_export.h"
/* provided for cgo's benefit */ /* provided for cgo's benefit */
LPCWSTR xWC_LISTVIEW = WC_LISTVIEW; LPWSTR xWC_LISTVIEW = WC_LISTVIEW;
static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data) static LRESULT CALLBACK tableSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
{ {
@ -37,7 +37,7 @@ void setTableSubclass(HWND hwnd, void *data)
xpanic("error subclassing Table to give it its own event handler", GetLastError()); xpanic("error subclassing Table to give it its own event handler", GetLastError());
} }
void tableAppendColumn(HWND hwnd, int index, LPCWSTR name) void tableAppendColumn(HWND hwnd, int index, LPWSTR name)
{ {
LVCOLUMNW col; LVCOLUMNW col;

View File

@ -33,14 +33,14 @@ extern HWND msgwin;
extern DWORD makemsgwin(char **); extern DWORD makemsgwin(char **);
/* comctl32_windows.c */ /* comctl32_windows.c */
extern DWORD initCommonControls(LPCWSTR, char **); extern DWORD initCommonControls(LPWSTR, char **);
/* these are listed as WINAPI in both Microsoft's and MinGW's headers, but not on MSDN for some reason */ /* these are listed as WINAPI in both Microsoft's and MinGW's headers, but not on MSDN for some reason */
extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR); extern BOOL (*WINAPI fv_SetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
extern BOOL (*WINAPI fv_RemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR); extern BOOL (*WINAPI fv_RemoveWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR);
extern LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM); extern LRESULT (*WINAPI fv_DefSubclassProc)(HWND, UINT, WPARAM, LPARAM);
/* controls_windows.c */ /* controls_windows.c */
extern HWND newWidget(LPCWSTR, DWORD, DWORD); extern HWND newWidget(LPWSTR, DWORD, DWORD);
extern void controlSetParent(HWND, HWND); extern void controlSetParent(HWND, HWND);
extern void controlSetControlFont(HWND); extern void controlSetControlFont(HWND);
extern LRESULT forwardCommand(HWND, UINT, WPARAM, LPARAM); extern LRESULT forwardCommand(HWND, UINT, WPARAM, LPARAM);
@ -71,26 +71,26 @@ extern void moveWindow(HWND, int, int, int, int);
/* window_windows.c */ /* window_windows.c */
extern DWORD makeWindowWindowClass(char **); extern DWORD makeWindowWindowClass(char **);
extern HWND newWindow(LPCWSTR, int, int, void *); extern HWND newWindow(LPWSTR, int, int, void *);
extern void windowClose(HWND); extern void windowClose(HWND);
/* common_windows.c */ /* common_windows.c */
extern LRESULT getWindowTextLen(HWND); extern LRESULT getWindowTextLen(HWND);
extern void getWindowText(HWND, WPARAM, LPCWSTR); extern void getWindowText(HWND, WPARAM, LPWSTR);
extern void setWindowText(HWND, LPCWSTR); extern void setWindowText(HWND, LPWSTR);
extern void updateWindow(HWND); extern void updateWindow(HWND);
extern void storelpParam(HWND, LPARAM); extern void storelpParam(HWND, LPARAM);
/* containers_windows.go */ /* containers_windows.go */
extern LPCWSTR xWC_TABCONTROL; extern LPWSTR xWC_TABCONTROL;
extern void setTabSubclass(HWND, void *); extern void setTabSubclass(HWND, void *);
extern void tabAppend(HWND, LPCWSTR); extern void tabAppend(HWND, LPWSTR);
extern void tabGetContentRect(HWND, RECT *); extern void tabGetContentRect(HWND, RECT *);
/* table_windows.go */ /* table_windows.go */
extern LPCWSTR xWC_LISTVIEW; extern LPWSTR xWC_LISTVIEW;
extern void setTableSubclass(HWND, void *); extern void setTableSubclass(HWND, void *);
extern void tableAppendColumn(HWND, int, LPCWSTR); extern void tableAppendColumn(HWND, int, LPWSTR);
extern void tableUpdate(HWND, int); extern void tableUpdate(HWND, int);
extern void tableAddExtendedStyles(HWND, LPARAM); extern void tableAddExtendedStyles(HWND, LPARAM);

View File

@ -60,7 +60,7 @@ DWORD makeWindowWindowClass(char **errmsg)
return 0; return 0;
} }
HWND newWindow(LPCWSTR title, int width, int height, void *data) HWND newWindow(LPWSTR title, int width, int height, void *data)
{ {
HWND hwnd; HWND hwnd;