Using ModPlug Plugin in your VB applications -------------------------------------------- First, you must have NPMOD32.DLL in your application directory, or provide the path where the file is located. OK. To get a basic player window up that loops the MOD over and over, put these declarations in a module. ****************************************************** * 1.75+ * Declare Function ModPlug_CreateEx Lib "npmod32.dll" (ByVal lpszArgs As String) As Long Declare Function ModPlug_Destroy Lib "npmod32.dll" (ByVal pPlugin As Long) As Long Declare Function ModPlug_SetWindow Lib "npmod32.dll" (ByVal pPlugin As Long, ByVal hwnd As Long) As Long Declare Function ModPlug_Load Lib "npmod32.dll" (ByVal pPlugin As Long, ByVal lpszFileName As String) As Long Declare Function ModPlug_Play Lib "npmod32.dll" (ByVal pPlugin As Long) As Long Declare Function ModPlug_Stop Lib "npmod32.dll" (ByVal pPlugin As Long) As Long * 1.80+ * Declare Function ModPlug_SetCurrentPosition Lib "npmod32.dll" (ByVal plugin As Long, ByVal nPos As Long) As Long Declare Function ModPlug_GetCurrentPosition Lib "npmod32.dll" (ByVal plugin As Long) As Long Declare Function ModPlug_GetVersion Lib "npmod32.dll" () As Long Declare Function ModPlug_IsPlaying Lib "npmod32.dll" (ByVal plugin As Long) As Long Declare Function ModPlug_IsReady Lib "npmod32.dll" (ByVal plugin As Long) As Long Declare Function ModPlug_GetMaxPosition Lib "npmod32.dll" (ByVal plugin As Long) As Long * 1.91+ * Declare Function ModPlug_SetVolume Lib "npmod32.dll" (ByVal plugin As Long, ByVal vol As Long) As Long Declare Function ModPlug_GetVolume Lib "npmod32.dll" (ByVal plugin As Long) As Long ****************************************************** NOTE! SetCurrentPosition, IsPlaying, and IsReady have not been tested yet and therefore may not work. (If they don't work, try replacing the "As Long" return type specifier with "As Boolean".) ****************************************************** Put this code in the general declarations section of the form. ****************************************************** Dim RetVal As Long Dim ModFileName$ ****************************************************** Then, put this code somewhere. This code can go anywhere in your application that you see fit. However, I like to put it in a command button. ****************************************************** Private Sub Command1_Click() ' EXTREMELY IMPORTANT FIRST STEP ' In order to get a MOD playing, you have to ' first create the plugin. Note that this ' does not actually display the plugin. However, ' this returned value is so important that we give ' it variable RetVal. RetVal = ModPlug_CreateEx ("loop|true") ' This next step gives the newly-created plugin ' a window hWnd to use. This return value ' isn't important; therefore, we give it variable ' x. X = ModPlug_SetWindow (RetVal, Form1.hWnd) ' This next step loads the MOD. The MOD can be ' of any type that the ModPlug Player supports. ' (MOD/S3M/IT/XM/669...) ModFileName$ = "MYMOD.MOD" 'remember to include full 'path if MOD is not in app 'directory X = ModPlug_Load (RetVal, ModFileName$) 'If all goes well, you can now play the MOD. X = ModPlug_Play (RetVal) End Sub ****************************************************** To stop the MOD, use ModPlug_Stop (it should be pretty self-explanatory.) When your application ends, or you want to completely stop the MOD Plugin, use this: ****************************************************** Private Sub Command2_Click() 'Stop the plugin. X = ModPlug_Stop(RetVal) 'Now, destroy the plugin window... X = ModPlug_Destroy(RetVal) End Sub ****************************************************** And now, to keep people from bugging me about this: The API declaration conversion process explained! OK, let's say you have a C++ declaration like this: BOOL WINAPI ModPlug_Load(LPVOID pPlugin, LPCSTR lpszFileName) 1. To convert it to VB, this is what you've got to do. First, consider the first two words of the C++ declaration: BOOL WINAPI This tells the C++ compiler (I think) that the function returns a value of type BOOL (boolean). In any case, this function returns a value, so VB calls them functions. (If the function did not return a value (C++ type void), then it would be called a subroutine, and we would use Declare Sub instead.) Declare Function 2. Next, we type the name of the function. Declare Function ModPlug_Load 3. OK. At this step, we can either tack on the function return value: Declare Function ModPlug_Load% (Notice that I use the Integer type, because although there is a boolean type value in VB, it only accepts VB's values for true and false, and C++ may be different.) Or we can just leave it the way it is and tack on the function value at the end. It doesn't matter. 4. Now we've got to tell VB where the DLL is. In this case, it's NPMOD32.DLL. (C++ doesn't seem to require DLL file locations. Anybody wanna tell me how C++ does it?) Declare Function ModPlug_Load Lib "npmod32.dll" 5. Now, we translate each parameter and vartype to VB declaration. A good explanation on how this is done, as well as a vartype table, can be found at: http://www.cyberhighway.com/~psy/vbthunder/reference/readcpp.htm Declare Function ModPlug_Load Lib "npmod32.dll" (ByVal pPlugin As Long, ByVal lpszFileName As String) 6. And, if you haven't done so already, tack on the return type. Declare Function ModPlug_Load Lib "npmod32.dll" (ByVal pPlugin As Long, ByVal lpszFileName As String) As Long or Declare Function ModPlug_Load% Lib "npmod32.dll" (ByVal pPlugin As Long, ByVal lpszFileName As String) 7. NOTE: Experienced VB programmers will know that you can substitute the vartype characters for the "As Long" and blah parts. Therefore, the "compressed version" of the ModPlug_Load declaration would be: Declare Function ModPlug_Load% Lib "npmod32.dll" (ByVal pPlugin!, ByVal lpszFileName$) ****************************************************** That's it! I would post a sample application with all the code and stuff, but all of the .DLLs that VB applications require make for a hefty download... not to mention version incompatiblities. ****************************************************** -- David Yip