Results 1 to 1 of 1

Thread: [2005] C to VB.Net translation experts only please

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    [2005] C to VB.Net translation experts only please

    I'm trying to convert a C structure that include function pointer into a VB.Net structure that contain delegates. (Only .Net 2.0 and 3.0 users should attempt this.) When I call a function in an unmanaged dll that fills the structure, I get the following error (nontrapable exception):

    Code:
    InvalidFunctionPointerInDelegate was detected
    Message: Invalid function pointer 0xb6390c91 was passed into the runtime to be converted to a delegate. Passing in invalid function pointers to be converted to delegates can cause crashes, corruption or data loss.
    Can anybody tell me how I got my delegate definitions or signatures messed up?

    Original structure:
    Code:
    typedef struct 
    {
    	int version;				// module type (IN_VER)
    	char *description;			// description of module, with version string
    
    	HWND hMainWindow;			// winamp's main window (filled in by winamp)
    	HINSTANCE hDllInstance;		// DLL instance handle (Also filled in by winamp)
    
    	char *FileExtensions;		// "mp3\0Layer 3 MPEG\0mp2\0Layer 2 MPEG\0mpg\0Layer 1 MPEG\0"
    								// May be altered from Config, so the user can select what they want
    	
    	int is_seekable;			// is this stream seekable? 
    	int UsesOutputPlug;			// does this plug-in use the output plug-ins? (musn't ever change, ever :)
    
    	void (*Config)(HWND hwndParent); // configuration dialog
    	void (*About)(HWND hwndParent);  // about dialog
    
    	void (*Init)();				// called at program init
    	void (*Quit)();				// called at program quit
    
    	void (*GetFileInfo)(char *file, char *title, int *length_in_ms); // if file == NULL, current playing is used
    	int (*InfoBox)(char *file, HWND hwndParent);
    	
    	int (*IsOurFile)(char *fn);	// called before extension checks, to allow detection of mms://, etc
    	// playback stuff
    	int (*Play)(char *fn);		// return zero on success, -1 on file-not-found, some other value on other (stopping winamp) error
    	void (*Pause)();			// pause stream
    	void (*UnPause)();			// unpause stream
    	int (*IsPaused)();			// ispaused? return 1 if paused, 0 if not
    	void (*Stop)();				// stop (unload) stream
    
    	// time stuff
    	int (*GetLength)();			// get length in ms
    	int (*GetOutputTime)();		// returns current output time in ms. (usually returns outMod->GetOutputTime()
    	void (*SetOutputTime)(int time_in_ms);	// seeks to point in stream (in ms). Usually you signal yoru thread to seek, which seeks and calls outMod->Flush()..
    
    	// volume stuff
    	void (*SetVolume)(int volume);	// from 0 to 255.. usually just call outMod->SetVolume
    	void (*SetPan)(int pan);	// from -127 to 127.. usually just call outMod->SetPan
    	
    	// in-window builtin vis stuff
    
    	void (*SAVSAInit)(int maxlatency_in_ms, int srate);		// call once in Play(). maxlatency_in_ms should be the value returned from outMod->Open()
    	// call after opening audio device with max latency in ms and samplerate
    	void (*SAVSADeInit)();	// call in Stop()
    
    
    	// simple vis supplying mode
    	void (*SAAddPCMData)(void *PCMData, int nch, int bps, int timestamp); 
    											// sets the spec data directly from PCM data
    											// quick and easy way to get vis working :)
    											// needs at least 576 samples :)
    
    	// advanced vis supplying mode, only use if you're cool. Use SAAddPCMData for most stuff.
    	int (*SAGetMode)();		// gets csa (the current type (4=ws,2=osc,1=spec))
    							// use when calling SAAdd()
    	void (*SAAdd)(void *data, int timestamp, int csa); // sets the spec data, filled in by winamp
    
    
    	// vis stuff (plug-in)
    	// simple vis supplying mode
    	void (*VSAAddPCMData)(void *PCMData, int nch, int bps, int timestamp); // sets the vis data directly from PCM data
    											// quick and easy way to get vis working :)
    											// needs at least 576 samples :)
    
    	// advanced vis supplying mode, only use if you're cool. Use VSAAddPCMData for most stuff.
    	int (*VSAGetMode)(int *specNch, int *waveNch); // use to figure out what to give to VSAAdd
    	void (*VSAAdd)(void *data, int timestamp); // filled in by winamp, called by plug-in
    
    
    	// call this in Play() to tell the vis plug-ins the current output params. 
    	void (*VSASetInfo)(int nch, int srate);
    
    
    	// dsp plug-in processing: 
    	// (filled in by winamp, called by input plug)
    
    	// returns 1 if active (which means that the number of samples returned by dsp_dosamples
    	// could be greater than went in.. Use it to estimate if you'll have enough room in the
    	// output buffer
    	int (*dsp_isactive)(); 
    
    	// returns number of samples to output. This can be as much as twice numsamples. 
    	// be sure to allocate enough buffer for samples, then.
    	int (*dsp_dosamples)(short int *samples, int numsamples, int bps, int nch, int srate);
    
    
    	// eq stuff
    	void (*EQSet)(int on, char data[10], int preamp); // 0-64 each, 31 is +0, 0 is +12, 63 is -12. Do nothing to ignore.
    
    	// info setting (filled in by winamp)
    	void (*SetInfo)(int bitrate, int srate, int stereo, int synched); // if -1, changes ignored? :)
    
    	Out_Module *outMod; // filled in by winamp, optionally used :)
    } In_Module;
    Translated to vb.net
    VB Code:
    1. <StructLayout(LayoutKind.Sequential)> _
    2.     Structure InModule
    3.         Public version As Integer
    4.         Public description As String
    5.  
    6.         Public hMainWindow As IntPtr
    7.         Public hDllInstance As IntPtr
    8.  
    9.         Public FileExtensions As String
    10.  
    11.         Public is_seekable As Integer
    12.         Public UsesOutputPlug As Integer
    13.  
    14.         Public Delegate Sub ConfigPTR(ByVal hwndParent As IntPtr)
    15.         Public Config As ConfigPTR
    16.  
    17.         Public Delegate Sub AboutPTR(ByVal hwndParent As IntPtr)
    18.         Public About As AboutPTR
    19.  
    20.         Public Delegate Sub InitPTR()
    21.         Public Init As InitPTR
    22.  
    23.         Public Delegate Sub QuitPTR()
    24.         Public Quit As QuitPTR
    25.  
    26.         Public Delegate Sub GetFileInfoPTR(ByRef file As String, ByRef title As String, ByRef lenght_in_ms As Integer)
    27.         Public GetFileInfo As GetFileInfoPTR
    28.  
    29.         Public Delegate Function InfoBoxPTR(ByRef file As String, ByVal hwndParent As IntPtr) As Integer
    30.         Public InfoBox As InfoBoxPTR
    31.  
    32.         Public Delegate Function IsOurFilePTR(ByRef fn As String) As Integer
    33.         Public IsOurFile As IsOurFilePTR
    34.  
    35.         '//Playback stuff
    36.         Public Delegate Function PlayPTR(ByRef fn As String) As Integer
    37.         Public Play As PlayPTR
    38.  
    39.         Public Delegate Sub PausePTR()
    40.         Public Pause As PausePTR
    41.  
    42.         Public Delegate Sub UnPausePTR()
    43.         Public UnPause As UnPausePTR
    44.  
    45.         Public Delegate Function IsPausedPTR() As Integer
    46.         Public IsPaused As IsPausedPTR
    47.  
    48.         Public Delegate Sub StopPTR()
    49.         Public [Stop] As StopPTR
    50.  
    51.         '//Time stuff
    52.         Public Delegate Function GetLengthPTR() As Integer
    53.         Public GetLength As GetLengthPTR
    54.  
    55.         Public Delegate Function GetOutputTimePTR() As Integer
    56.         Public GetOutputTime As GetOutputTimePTR
    57.  
    58.         Public Delegate Sub SetOutputTimePTR(ByVal time_in_ms As Integer)
    59.         Public SetOutputTime As SetOutputTimePTR
    60.  
    61.         '//Volume stuff
    62.         Public Delegate Sub SetVolumePTR(ByVal volume As Integer)
    63.         Public SetVolume As SetVolumePTR
    64.  
    65.         Public Delegate Sub SetPanPTR(ByVal pan As Integer)
    66.         Public SetPan As SetPanPTR
    67.  
    68.         '//In-window builtin vis stuff
    69.         Public Delegate Sub SAVSAInitPTR(ByVal maxlatency_in_ms As Integer, ByVal srate As Integer)
    70.         Public SAVSAInit As SAVSAInitPTR
    71.  
    72.         Public Delegate Sub SAVSADeInitPTR()
    73.         Public SAVSADeInit As SAVSADeInitPTR
    74.  
    75.         '//Simple vis supplying mode
    76.         Public Delegate Sub SAAddPCMDataPTR(ByRef PCMData As Byte(), ByVal nch As Integer, ByVal bps As Integer, ByVal timestamp As Integer)
    77.         Public SAAddPCMData As SAAddPCMDataPTR
    78.  
    79.         '//Advanced vis supplying mode
    80.         Public Delegate Function SAGetModePTR() As Integer
    81.         Public SAGetMode As SAGetModePTR
    82.  
    83.         Public Delegate Sub SAAddPTR(ByRef data As Byte(), ByVal timestamp As Integer, ByVal csa As Integer)
    84.         Public SAAdd As SAAddPTR
    85.  
    86.         '//vis stuff (plug-in)
    87.         '//simple vis supplying mode
    88.         Public Delegate Sub VSAAddPCMDataPTR(ByRef PCMData As Byte(), ByVal nch As Integer, ByVal bps As Integer, ByVal timestamp As Integer)
    89.         Public VSAAddPCMData As VSAAddPCMDataPTR
    90.  
    91.         '//advanced vis supplying mode
    92.         Public Delegate Function VSAGetModePTR(ByRef specNch As Integer, ByRef waveNch As Integer) As Integer
    93.         Public VSAGetMode As VSAGetModePTR
    94.  
    95.         Public Delegate Sub VSAAddPTR(ByRef data As Byte(), ByVal timestamp As Integer)
    96.         Public VSAAdd As VSAAddPTR
    97.  
    98.         Public Delegate Sub VSASetInfoPTR(ByVal nch As Integer, ByVal srate As Integer)
    99.         Public VSASetInfo As VSASetInfoPTR
    100.  
    101.         '//dsp plug-in processing:
    102.         '//(filled in by winamp, called by input plug)
    103.  
    104.         Public Delegate Function dsp_isactivePTR() As Integer
    105.         Public dsp_isactive As dsp_isactivePTR
    106.  
    107.         Public Delegate Function dsp_dosamplesPTR(ByRef samples As Short, ByVal numsamples As Integer, ByVal bps As Integer, ByVal nch As Integer, ByVal srate As Integer) As Integer
    108.         Public dsp_dosamples As dsp_dosamplesPTR
    109.  
    110.         '//eq stuff
    111.         Public Delegate Sub EQSetPTR(ByVal [on] As Integer, ByVal data As Byte(), ByVal preamp As Integer) 'data is limited to 10 elements
    112.         Public EQSet As EQSetPTR
    113.  
    114.         '//info setting
    115.         Public Delegate Sub SetInfoPTR(ByVal bitrate As Integer, ByVal srate As Integer, ByVal stereo As Integer, ByVal synched As Integer)
    116.         Public SetInfo As SetInfoPTR
    117.  
    118.         Public Out_Mod As WinampOutputPlugin.OutModule
    119.     End Structure

    Let me know if more information is required.
    Last edited by agent; Dec 7th, 2006 at 09:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width