1. C_func problems...

Can anybody tell me why the following code has a machine-level
exception error when run?

The relevant msdn entry is here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createmutex.asp

Very frustrating...

constant NULL = -1
include dll.e
include machine.e
constant kernel32 = open_dll("kernel32")
--HANDLE CreateMutex(
--  LPSECURITY_ATTRIBUTES lpMutexAttributes,
--  BOOL bInitialOwner,
--  LPCTSTR lpName
--);
constant xCreateMutex = define_c_func(kernel32, "CreateMutexA",
{C_POINTER, C_CHAR, C_POINTER}, C_INT	)

function createMutex(sequence name)
	atom ret, str
	str = allocate_string(name)
	ret = c_func(xCreateMutex, {NULL, 0, str})
	free(str)
	return ret
end function

? createMutex("testing")


-- 
MrTrick

new topic     » topic index » view message » categorize

2. Re: C_func problems...

NULL should be 0, not -1

-1 is sent to a C function as #FFFFFFFF and it thinks that's a memory
address (pointer) of a the structure LPSECURITY_ATTRIBUTES. 0, on the
other hand, is an empty memory address.


On Thu, 25 Nov 2004 17:04:10 +1100, Patrick Barnes <mrtrick at gmail.com> wrote:
> 
> Can anybody tell me why the following code has a machine-level
> exception error when run?
> 
> The relevant msdn entry is here:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createmutex.asp
> 
> Very frustrating...
> 
> }}}
<eucode>
> constant NULL = -1
> include dll.e
> include machine.e
> constant kernel32 = open_dll("kernel32")
> --HANDLE CreateMutex(
> --  LPSECURITY_ATTRIBUTES lpMutexAttributes,
> --  BOOL bInitialOwner,
> --  LPCTSTR lpName
> --);
> constant xCreateMutex = define_c_func(kernel32, "CreateMutexA",
> {C_POINTER, C_CHAR, C_POINTER}, C_INT   )
> 
> function createMutex(sequence name)
>        atom ret, str
>        str = allocate_string(name)
>        ret = c_func(xCreateMutex, {NULL, 0, str})
>        free(str)
>        return ret
> end function
> 
> ? createMutex("testing")
> </eucode>
{{{

> 
> --
> MrTrick
> 
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: C_func problems...

BOOL bInitialOwner

BOOL should be C_INT

Bernie

My files in archive:
w32engin.ew mixedlib.e eu_engin.e win32eru.ew

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

4. Re: C_func problems...

On Thu, 25 Nov 2004 09:22:23 -0800, Bernie Ryan <guest at rapideuphoria.com>
wrote:
> BOOL bInitialOwner
> 
> BOOL should be C_INT

Why C_INT? What's wrong with C_CHAR?

-- 
MrTrick
-------------------------------------------------------------------------------------
magnae clunes mihi placent, nec possum de hac re mentiri.

new topic     » goto parent     » topic index » view message » categorize

5. Re: C_func problems...

Patrick Barnes wrote:
> 
> On Thu, 25 Nov 2004 09:22:23 -0800, Bernie Ryan <guest at rapideuphoria.com>
> wrote:
> > BOOL bInitialOwner
> > 
> > BOOL should be C_INT
> 
> Why C_INT? What's wrong with C_CHAR?
> 
> -- 
> MrTrick
>
> -------------------------------------------------------------------------------------
> magnae clunes mihi placent, nec possum de hac re mentiri. 
> 
> 

Because if you ever use it in  a structure as C_CHAR windows 
will be passed the wrong size structure, so I suggest that
you always use C_INT, it is not absolutely necessasry in this case. 

Bernie

My files in archive:
w32engin.ew mixedlib.e eu_engin.e win32eru.ew

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

6. Re: C_func problems...

On Thu, 25 Nov 2004 14:38:11 -0800, Bernie Ryan <guest at rapideuphoria.com>
wrote:
> Patrick Barnes wrote:
> >
> > On Thu, 25 Nov 2004 09:22:23 -0800, Bernie Ryan <guest at rapideuphoria.com>
> > wrote:
> > > BOOL bInitialOwner
> > >
> > > BOOL should be C_INT
> >
> > Why C_INT? What's wrong with C_CHAR?
> 
> Because if you ever use it in  a structure as C_CHAR windows
> will be passed the wrong size structure, so I suggest that
> you always use C_INT, it is not absolutely necessasry in this case.
> 

Okay, thanks. It did turn out that the NULL being defined improperly
was the issue.

-- 
MrTrick

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu