Awesome, thanks for the examples. I'll take a look.
On Monday, 7 September 2015 11:37:24 UTC-4, Isaiah wrote:
>
> Yup, that's the hacky solution :)
>
> I modified my example after copying it and didn't fix the last part.
> Here's a working version:
>
>
> julia> err = ccall( (:midiOutGetDevCapsA, :Winmm), Uint64, (Ptr{Uint64},
> Ref{Mid
> iOutCaps}, Uint32), 0, output_struct, sizeof(output_struct))
> WARNING: convert(::Type{Ptr}, ::Int64) methods should be converted to be
> methods
> of unsafe_convert
> in depwarn at deprecated.jl:73
> in unsafe_convert at no file:398
> in anonymous at no file
> while loading no file, in expression starting on line 0
> 0x0000000000000000
>
> julia> bytestring(Ptr{Cchar}(pointer_from_objref(output_struct[].szPname)))
> "Microsoft GS Wavetable Synth"
>
>
> (for some reason I haven't investigated yet, passing the device id as a
> Ref doesn't work)
>
> Possibly of interest, I have some example code calling a few Win32 API
> functions here:
>
> https://github.com/ihnorton/Win32GUIDemo.jl
> https://github.com/ihnorton/COMCall.jl
>
> (there are also some examples in base, the implementation of `download`
> for example)
>
> On Mon, Sep 7, 2015 at 10:29 AM, Joel Hobson <[email protected]
> <javascript:>> wrote:
>
>> Sorry about the last post - I'm new, so it was caught in the moderation
>> filter. I actually wrote it before Tony and Isaiah posted.
>> Isaiah - That looks promising, thanks! It's been a long time since I've
>> used C, so I completely missed that szPname isn't a pointer.
>>
>> On Sunday, 6 September 2015 17:37:01 UTC-4, Joel Hobson wrote:
>>
>>> Hi all,
>>>
>>> I'm trying to use some C functions, but I'm running into trouble using
>>> the results.
>>>
>>> This is the function I'm trying to call:
>>> https://msdn.microsoft.com/en-us/library/dd798469(v=vs.85).aspx
>>> And this is the struct that it's expecting a pointer to:
>>> https://msdn.microsoft.com/en-us/library/dd798467(v=vs.85).aspx
>>>
>>> Here's my struct definition in Julia:
>>>
>>> type MidiOutCaps
>>> wMid::Uint16
>>> wPid::Uint16
>>> vDriverVersion::Uint32
>>> szPname::Ptr{Uint8}
>>> wTechnology::Uint16
>>> wVoices::Uint16
>>> wNotes::Uint16
>>> wChannelMask::Uint16
>>> dwSupport::Uint32
>>>
>>> MidiOutCaps() = new(0, 0, 0, Array(Uint8, 32), 0, 0, 0, 0, 0)
>>> end
>>>
>>> And the function for loading it:
>>>
>>> function getoutputdeviceswindows()
>>> numberofdevices = ccall( (:midiOutGetNumDevs, :Winmm), Int32, ())
>>>
>>> for i in [0:numberofdevices-1]
>>> output_struct = MidiOutCaps()
>>>
>>> err = ccall( (:midiOutGetDevCapsA, :Winmm), Uint32,
>>> (Ptr{Uint32}, Ptr{MidiOutCaps}, Uint32), i, &output_struct,
>>> sizeof(output_struct))
>>>
>>> println("Err is $(err)")
>>> println("Result is $(output_struct)")
>>>
>>> println("Result name is $(unsafe_load(output_struct.szPname,
>>> 0))")
>>> end
>>> end
>>>
>>> Both ccalls execute without error, and it appears to populate the struct
>>> correctly, but when I try to do an unsafe load on the szPname, Julia
>>> crashes and I get this:
>>>
>>> Please submit a bug report with steps to reproduce this fault, and any
>>> error messages that follow (in their entirety). Thanks.
>>> Exception: EXCEPTION_ACCESS_VIOLATION at 0xdbc6d34 -- unsafe_load at
>>> pointer.jl:45
>>> unsafe_load at pointer.jl:45
>>> jlcall_unsafe_load_1323 at (unknown line)
>>> jl_apply_generic at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> jl_interpret_toplevel_expr at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> jl_interpret_toplevel_thunk_with at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> jl_eval_with_compiler_p at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> jl_f_top_eval at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> eval_user_input at REPL.jl:53
>>> jlcall_eval_user_input_1054 at (unknown line)
>>> jl_apply_generic at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> anonymous at task.jl:95
>>> jl_handle_stack_switch at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> julia_trampoline at
>>> C:\Users\Joel\AppData\Local\Julia-0.3.9\bin\libjulia.dll (unknown line)
>>> unknown function (ip: 4202784)
>>> unknown function (ip: 4199370)
>>> unknown function (ip: 4199672)
>>> BaseThreadInitThunk at C:\WINDOWS\system32\KERNEL32.DLL (unknown line)
>>> RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
>>> RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
>>>
>>> I suspect that it's a problem with my code and not Julia, which is why I
>>> haven't submitted a bug report yet.
>>>
>>> I've tried just setting szPname to 0 instead of an array, and I've tried
>>> different index values for unsafe_load, but no luck. Any ideas where I'm
>>> going wrong? The only other issue I can see is that MSDN defines szPname to
>>> be an array of TCHARs, but according to the MSDN, TCHAR is just a char.
>>> https://msdn.microsoft.com/en-us/library/office/cc842072.aspx
>>>
>>> Thanks!
>>>
>>>
>>>
>>>
>