Passing parameters to windows kernel32 dll functions

289 views
Skip to first unread message

Terry Bayne

unread,
Aug 7, 2012, 11:06:11 AM8/7/12
to golan...@googlegroups.com
I am having a problem passing a structure to a windows DLL function:

BOOL WINAPI FillConsoleOutputAttribute(
  __in   HANDLE hConsoleOutput,
  __in   WORD wAttribute,
  __in   DWORD nLength,
  __in   COORD dwWriteCoord,
  __out  LPDWORD lpNumberOfAttrsWritten
);

The parameter that I am having an issue with is "COORD dwWriteCoord".

Here is the type definition I am using for COORD:

Coord struct {
	X, Y int16
	}

What I believe is that I need to convert that structure to a DWORD, and that to uintptr, but I am obviously missing something.

Current function where I am using this:

func FillConsoleOutputAttribute(Handle uintptr, wAttrib word, nLength DWord, dwWriteCoord Coord) (result DWord, err error) {

	var lpNumberofAttrsWritten DWord
	var dwCoord DWord = uintptr(dwWriteCoord) // This doesn't compile

	ret, _, callErr := fillConsoleOutputAttribute.Call(Handle, uintptr(wAttrib), uintptr(nLength), uintptr(dwCoord), uintptr(unsafe.Pointer(&lpNumberofAttrsWritten)))

	if ret == 0 {
        	abort2("FillConsoleOutputAttribute()", callErr)
	}

	result = lpNumberofAttrsWritten
	err = nil
	return
}

I could post all the code, but it's not usable on Play, so figured I would wait until someone requests the whole thing.

Any ideas or suggestions would be appreciated.

Thanks
Terry

minux

unread,
Aug 7, 2012, 11:22:20 AM8/7/12
to Terry Bayne, golan...@googlegroups.com
On Tue, Aug 7, 2012 at 11:06 PM, Terry Bayne <trb...@gmail.com> wrote:
BOOL WINAPI FillConsoleOutputAttribute(
  __in   HANDLE hConsoleOutput,
  __in   WORD wAttribute,
  __in   DWORD nLength,
  __in   COORD dwWriteCoord,
  __out  LPDWORD lpNumberOfAttrsWritten
);
The parameter that I am having an issue with is "COORD dwWriteCoord".
Here is the type definition I am using for COORD:
Coord struct {
	X, Y int16
	}
What I believe is that I need to convert that structure to a DWORD, and that to uintptr, but I am obviously missing something.
Current function where I am using this:
func FillConsoleOutputAttribute(Handle uintptr, wAttrib word, nLength DWord, dwWriteCoord Coord) (result DWord, err error) {

	var lpNumberofAttrsWritten DWord
	var dwCoord DWord = uintptr(dwWriteCoord) // This doesn't compile
why not just use ... = uintptr(dwWriteCoord.X) + uintptr(dwWriteCoord.Y) << 16 ? 

Terry Bayne

unread,
Aug 7, 2012, 12:04:11 PM8/7/12
to golan...@googlegroups.com, Terry Bayne

On Tuesday, August 7, 2012 10:22:20 AM UTC-5, minux wrote:

why not just use ... = uintptr(dwWriteCoord.X) + uintptr(dwWriteCoord.Y) << 16 ? 

That did the trick.  Obvious now that I think about it.

Thank you.
Terry 
Reply all
Reply to author
Forward
0 new messages