Skip to main content
gamedev.net
🔒 Locked

C function returning to VB

Started by DoChEx 0 replies 150+ views
Original Post
DoChEx
DoChEx
Hi, I need some help with a return value from C to VB. I have a DLL and it returns a struct type, can I get this information into VB? This is the function I’m calling. extern "C" __declspec(dllexport) VideoInfo* __stdcall openMPEG2Source(char* file) Here is the struct returned. struct VideoInfo { int width, height; // width=0 means no video unsigned fps_numerator, fps_denominator; int num_frames; enum { UNKNOWN=0, BGR24=0x13, BGR32=0x14, YUY2=0x22 }; unsigned char pixel_type; bool field_based; int audio_samples_per_second; // 0 means no audio int num_audio_samples; bool stereo, sixteen_bit; // useful functions of the above bool HasVideo() const { return !!width; } bool HasAudio() const { return !!audio_samples_per_second; } bool IsRGB() const { return !!(pixel_type&0x10); } bool IsRGB24() const { return pixel_type == BGR24; } bool IsRGB32() const { return pixel_type == BGR32; } bool IsYUV() const { return !!(pixel_type&0x20); } bool IsYUY2() const { return pixel_type == YUY2; } int BytesFromPixels(int pixels) const { return pixels * (pixel_type&7); } int RowSize() const { return BytesFromPixels(width); } int BitsPerPixel() const { return (pixel_type&7) * 8; } int BMPSize() const { return height * ((RowSize()+3) & -4); } int AudioSamplesFromFrames(int frames) const { return int(__int64(frames) * audio_samples_per_second * fps_denominator / fps_numerator); } int FramesFromAudioSamples(int samples) const { return int(__int64(samples) * fps_numerator / fps_denominator / audio_samples_per_second); } int AudioSamplesFromBytes(int bytes) const { return bytes >> (stereo + sixteen_bit); } int BytesFromAudioSamples(int samples) const { return samples << (stereo + sixteen_bit); } int BytesPerAudioSample() const { return BytesFromAudioSamples(1); } // useful mutator void SetFPS(unsigned numerator, unsigned denominator) { unsigned x=numerator, y=denominator; while (y) { // find gcd unsigned t = x%y; x = y; y = t; } fps_numerator = numerator/x; fps_denominator = denominator/x; } }; Here’s my VB code Public Type tVideoInfo ''int Width As Long Height As Long ''unsigned fps_numerator As Long fps_denominator As Long ''int num_frames As Long ''enum ''unsigned char pixel_type As Byte ''bool field_based As Long ''int audio_samples_per_second As Long num_audio_samples As Long ''bool stereo As Long sixteen_bit As Long End Type Public Declare Function m2d_OpenMPEG2 Lib "mpeg2dec.dll" Alias "_openMPEG2Source@4" (ByVal strFileName As String) As tVideoInfo Any help would be great! Cheers.
Sailorstick
Sailorstick
Specifically what problems are you having?
I''ve found I''ve never needed extern "C" __declspec(dllexport) just stdcall and a .def file with undecorated names. Also in the VB declare statement I don''t think think the decorations are necessary. (At least, I have never needed them and nor do you need them for Win32 API)
Are you at least able to get some of the structure?

''Your theory of a donut shaped universe is intriguing Homer'' - Stephen Hawking

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.