[C] Calling function of another dll from my C dll (for WinAmp Vis Plugin)
Firstly, I'm NOT a Windows C programmer. Last time I used C was long time ago in college. I know only DOS based C programming with TurboC++.
So, basically I'm asking you to give me some C0d. ;)
I'm making a visualization module for WinAmp. My base code is "\vis\vis_test\SVIS.C" from WinAmp SDK (237kb only).
As I don't know C/CPP programming on Windows, my idea is to create a standard dll using VB and pass it memDC variable and WinAMPVisModule structure.
That way, I can draw the graphics from inside my VB dll.
Here is what I want in the render1 function of SVIS.C:
C Code:
int render1(struct winampVisModule *this_mod)
{
long lb, pa;
//map 'user32' into the address space of the calling process.
lb = LoadLibrary("Project1.dll");
//retrieve the address of 'SetWindowTextA'
pa = GetProcAddress(lb, "WinAmpVisTest");
// HOW TO CALL THE FOLLOWING PROCEDURE FROM MY DLL ?
//Public Sub WinAmpVisTest(MemDC As Long, this_mod As WinAMPVisModule)
//unmap the library's address
FreeLibrary (lb);
return 0;
}
Here is WinAmpVisTest from my VB dll:
vb Code:
Public Sub WinAmpVisTest(MemDC As Long, this_mod As WinAMPVisModule)
' Draw on the memDC
End Sub
And here is the WinAMPVisModule in VB
vb Code:
Public Type WinAMPVisModule 'Most comments here are verbatim from VIS mini-SDK.
Description As String 'description of module
hWndParent As Long 'parent window (filled in by calling app)
hDLLInstance As Long 'instance handle to DLL (filled this in)
sRate As Long 'sample rate (filled in by calling app)
nCh As Long 'number of channels (filled in...)
LatencyMs As Long 'latency from call of RenderFrame to actual drawing
'(calling app looks at this value when getting data)
DelayMs As Long 'delay between calls in ms
'the data is filled in according to the respective Nch entry
SpectrumNch As Long
WaveformNch As Long
SpectrumData(0 To 575, 0 To 1) As Byte
WaveformData(0 To 575, 0 To 1) As Byte
'These function pointers all get passed one argument -- a pointer to a
'winampVisModule struct (type).
ConfigFP As Long 'configuration dialog function -- returns void
InitFP As Long '0 on success, creates window, etc. -- returns int
RenderFP As Long '0 on success, 1 if vis should end -- returns int
QuitFP As Long 'call when done
UserDataP As Long 'user data, optional
End Type
PowerBasic version of SVIS.C code can be found here.
Thanks in advance for any kind of input. :)
Re: [C] Calling function of another dll from my C dll (for WinAmp Vis Plugin)
so what have you got in mind, aren't there heaps of visualisations already? av and milk are very nice and i haven't been through all the plug ins yet, and who knows what is going to happen in the next 12 months or so ;) also there doesn't seem to be a gui for the visualisations as you pointed out in any skin except modern :( besides if you want to do a good job on it wouldn't you write your own media player from scratch?
Re: [C] Calling function of another dll from my C dll (for WinAmp Vis Plugin)
I wanted something new to try.
Besides, there is no fullscreen LED spectrum analyzer like the one I want. So I wanted to make one.
I'm able to SendMessage the memDC to another VB exe and can work on it. But I'm not able to call function of another dll from inside C dll.
I tried similar to this code, but it is unable to load the library. The erormessage I printed with TextOut is displayed on the visualization screen.
In VB:
vb Code:
Public Sub WinAmpVisTest(memDC as Long)
' Do something
End Sub
In C:
C Code:
// render function for oscilliscope. Returns 0 if successful, 1 if visualization should end.
int render1(struct winampVisModule *this_mod)
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL, "WinAmpVisTest");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef int (__stdcall * pICFUNC)(HDC);
pICFUNC MyFunction;
if (hGetProcIDDLL==NULL)
{
TextOut(memDC, 0,0, "Can not open the Library",24);
return 0;
}
MyFunction = (pICFUNC)lpfnGetProcessID;
/* The actual call to the function contained in the dll */
MyFunction(memDC);
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
/* The return val from the dll */
return 0;
}