Hi! I'll preface this by saying I'm a novice with C++ and the majority of my work is VB .Net, although in the past month I've had to take a self-crash-course in C++ for a project with some severely short deadlines, so I'm able to grasp basic C++ concepts. My C++ work at the moment involves writing my own C++ DLL to act as a join between a VB .Net application I am writing and an SDK that is designed for and writen in, C++ (I unfortunately lack the time to a solid course in C# and work with a more compatible pair of languages). The reason I'm writing this DLL is because certain uses of data types (unions being my biggest problem) used by the SDK aren't replicable in VB .Net (at least not to the best of my ability), and it's been easier to reproduce the functionality I need in C++ and send the data my VB .Net app needs back up the line. Coming to my problem, the SDK is for a Canon line of digital cameras, and is used for manipulating the camera from a PC (taking pictures and getting live video, with a whole bunch of additional features on the camera you can access). My goal is to be able to take pictures (which I've fully accomplished), and get live video so that the user of my application can see what they're going to take a picture of before they do so. To put this in context, the app is for taking security badge photos. The SDK handles video capture as sending to the PC what the digital view-finder on the camera can 'see', and it does this at a frame rate I think to be on the order of 25-29 fps, via an event call procedure I vaguely understand. Basically I create a pointer for the event that the initial function recognizes and then runs every time a frame of data is sent in from the camera, and then I write what code I want to in that event to display images. The event's parameters are a void field that is a buffer holding the data of the image, an unsigned long field holding the size of the buffer, another unsigned long field for the format (a 0 or 1 that I set as a seperate parameter of the initial function call to set the images coming back as bitmap or jpeg format, I'm using bitmap), and one more unsigned long field that I can use at my hearts content, but doesn't play any role in my needs. Basically, I want to take what's in that buffer, and get it to my VB .Net application as a Byte array (in the .Net sense of the type) that I can then turn via a .Net memory-stream that data into a bitmap image (that final step being something I've done countless times before). My attempts at the moment hav
Daniel Gow
Posts
-
Data Buffer into a VB .Net Byte Array -
Issue with GetProcAddress (Resolved)Thanks so much for your reply! I unfortunately can't say that my DLL is working, but the problem I have now is one in relation to the SDK, not with C++ or the help you offered. The 'extern "C" __declspec..." line did the trick fine, and I'm starting to get the hang of this! Thanks again.
-
Issue with GetProcAddress (Resolved)Thanks for your reply! I'm sure I never would have figured that out on my own...and I understand it vaguely enough for it to make sense to me - which is enough. It works great too, builds properly and all that and I added a little bit of error handling (such as it is) to the mix. One problem I'm having though is that my VB app can't find the function in the DLL. Is there a special way I need to declare the function so that it's what I'd call "Public" in a VB .Net sense, or visible beyond the scope of the inner workings of the DLL? At the moment the function starts as...
cdError ReturnCamera(cdHandle hEnum, cdHandle &hnd)
- cdError is just another unsigned long. Thanks again! -
Issue with GetProcAddress (Resolved)Hello! I'll preface this by saying I'm a complete novice with C++; the bulk of my programming has been in VB 5/6 and VB .Net, but I have an issue with an SDK that is designed for C++, and I need it to work with VB.Net. My issue is this; two of the functions in the DLL supplied with the SDK use a structure that has a datatype in it that is a Union (unions, of course, aren't that well supported in VB .Net). So, I decided the best route was to create my own C++ DLL that would handle the two functions that need to use this Union datatype, meaning all I would need to do is supply an input parameter (an integer in my case) and recieve and output parameter back (another integer). Calling the functions from VB .Net is easy, but that's not my problem. I've written the C++ DLL basically by copying and pasting from the C++ header files supplied with the SDK, as that made the most sense given my lack of C++ knowledge. I have a header file that has all of the datatype definitions, an additional header file for the structure and union definitions, and then a ".cpp" file for the actual function call:
void ReturnTheDataINeed(cdHandle hEnum, cdHandle &hnd) { HINSTANCE hLib; cdError err; cdHEnum hEnumDevice; cdSourceInfo* pSourceInfo; cdSourceInfo SSrcInfo; cdHEnum hNext; cdEnumDeviceNext NextDevice; hLib = LoadLibrary("CDSDK.dll"); NextDevice = (cdEnumDeviceNext)GetProcAddress(hLib,"cdEnumDeviceNext"); pSourceInfo= new cdSourceInfo; err = NextDevice(hEnum, pSourceInfo); //err = cdOpenSource( &SSrcInfo, &hEnumDevice); FreeLibrary(hLib); hnd = hEnumDevice; };
These are the type definitions (also copied from the SDK)...typedef unsigned long cdError; typedef unsigned long cdHEnum;
- cdSourceInfo is a structure that holds data about the device, and I can supply the definition if it will help. cdEnumDeviceNext is a function pointer as follows...this is copied out of the SDK's header files under 'function pointers'.typedef cdError cdSTDCALL cdEnumDeviceNext( cdHEnum hEnum, cdSourceInfo* pSourceInfo );
cdSTDCALL is defined as this:#define cdSTDCALL __stdcall
And finally, I have the second function (cdOpenSource) commented out because...this dll does not build. When I attempt to build it, this line:NextDevice = (cdEnumDeviceNext)GetProcAddress(hLib,"cdEnumDeviceNext");
...throws the error "C2066: cast to function type is illegal" and what I pres