[PLUG-Devel] Connect wrapper in c (was OT: C programmers....)
Scott Harris
harris_s at ociweb.com
Fri Jun 19 11:25:23 MST 2009
You could do that in several ways:
1) make the g_wiimote object global to the methods:
/* static makes the handle file scope so it will not be visible outside
of this file */
static g_wiimote handle;
connect(){ connect to wiimote }
main(){ call connect(), perform actions on that handle}
2) or even better pass in the address of the handle and use it:
connect(g_wiimote* handle) { connect to wiimote using *handle }
main() { g_wiimote handle; call connect(&handle); perform actions on handle}
// if you are actully using C++ instead of C then you could pass by
reference (instead of by pointer).
Regards,
Scott
James Finstrom wrote:
> Greetings,
>
> The original email is below. but I would like to better explain what I
> want and I am a C newb so my terminology can be assumed incorrect...
>
> I have a program I am putting together that basicly connects the
> gphoto library to the cwiid library. I am currently connecting the
> wiimote in main(). What I want to do is move the connection of the
> wiimote out of main but still refer to the handle in main. So right
> now in main i connect to the wiimote and it creates g_wiimote. I then
> basicly read/write to g_wiimote. What I want to do is move that block
> of code that does the connect out of main to a function
> do_connect_wiimote() which will exicute that block of code and return
> g_wiimote to main so I can read/write to it.
>
> Thanks in advance for not bashing the newb :)
>
>
> Original users email:
> Greetings all,
>
> I am writing app that allows me to control my canon SLR with my
> wiimote. I am trying to figure out how to call a function in main that
> generats a handle then returns the handle to main
>
>
> Concept:
>
> connect(){ connect to wiimote and return handle foo}
>
> main(){ call connect(), get handle, perform actions on that handle}
>
>
> James Finstrom
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> PLUG-devel mailing list - PLUG-devel at lists.PLUG.phoenix.az.us
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-devel
>
--
----------------------------------------------------
Scott Harris, Principal Software Engineer
Object Computing, Inc. (OCI)
480-752-0042 x207 Arizona
http://www.ociweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5399 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.PLUG.phoenix.az.us/pipermail/plug-devel/attachments/20090619/22095f17/attachment.bin
More information about the PLUG-devel
mailing list