Results 1 to 3 of 3

Thread: [C] Calling function of another dll from my C dll (for WinAmp Vis Plugin)

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Arrow [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:
    1. int render1(struct winampVisModule *this_mod)
    2. {
    3.  
    4.     long lb, pa;
    5.  
    6.     //map 'user32' into the address space of the calling process.
    7.     lb = LoadLibrary("Project1.dll");
    8.  
    9.     //retrieve the address of 'SetWindowTextA'
    10.     pa =  GetProcAddress(lb, "WinAmpVisTest");
    11.  
    12.     // HOW TO CALL THE FOLLOWING PROCEDURE FROM MY DLL ?
    13.     //Public Sub WinAmpVisTest(MemDC As Long, this_mod As WinAMPVisModule)
    14.  
    15.     //unmap the library's address
    16.     FreeLibrary (lb);
    17.  
    18.     return 0;
    19. }

    Here is WinAmpVisTest from my VB dll:
    vb Code:
    1. Public Sub WinAmpVisTest(MemDC As Long, this_mod As WinAMPVisModule)
    2.      ' Draw on the memDC
    3. End Sub

    And here is the WinAMPVisModule in VB
    vb Code:
    1. Public Type WinAMPVisModule 'Most comments here are verbatim from VIS mini-SDK.
    2.  
    3.     Description  As String   'description of module
    4.     hWndParent   As Long         'parent window (filled in by calling app)
    5.     hDLLInstance As Long         'instance handle to DLL (filled this in)
    6.     sRate        As Long         'sample rate (filled in by calling app)
    7.     nCh          As Long         'number of channels (filled in...)
    8.     LatencyMs    As Long         'latency from call of RenderFrame to actual drawing
    9.     '(calling app looks at this value when getting data)
    10.     DelayMs      As Long         'delay between calls in ms
    11.     'the data is filled in according to the respective Nch entry
    12.     SpectrumNch As Long
    13.     WaveformNch As Long
    14.     SpectrumData(0 To 575, 0 To 1) As Byte
    15.     WaveformData(0 To 575, 0 To 1) As Byte
    16.     'These function pointers all get passed one argument -- a pointer to a
    17.     'winampVisModule struct (type).
    18.     ConfigFP As Long        'configuration dialog function -- returns void
    19.     InitFP As Long          '0 on success, creates window, etc. -- returns int
    20.     RenderFP As Long        '0 on success, 1 if vis should end -- returns int
    21.     QuitFP As Long          'call when done
    22.     UserDataP As Long       'user data, optional
    23. End Type

    PowerBasic version of SVIS.C code can be found here.


    Thanks in advance for any kind of input.
    Last edited by iPrank; May 29th, 2007 at 03:38 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    Banned learning c's Avatar
    Join Date
    Mar 2007
    Location
    canberra (australia's capital)
    Posts
    198

    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?

  3. #3

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. Public Sub WinAmpVisTest(memDC as Long)
    2.      ' Do something
    3. End Sub

    In C:
    C Code:
    1. // render function for oscilliscope. Returns 0 if successful, 1 if visualization should end.
    2. int render1(struct winampVisModule *this_mod)
    3. {
    4.    /* get handle to dll */
    5.    HINSTANCE hGetProcIDDLL = LoadLibrary("Project1.dll");
    6.  
    7.  
    8.    /* get pointer to the function in the dll*/
    9.    FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL, "WinAmpVisTest");
    10.  
    11.    /*
    12.     Define the Function in the DLL for reuse. This is just prototyping
    13.     the dll's function. A mock of it. Use "stdcall" for maximum
    14.     compatibility.
    15.    */
    16. typedef int (__stdcall * pICFUNC)(HDC);
    17.    pICFUNC MyFunction;
    18.  
    19.    
    20.     if (hGetProcIDDLL==NULL)
    21.     {
    22.         TextOut(memDC, 0,0, "Can not open the Library",24);
    23.         return 0;
    24.     }
    25.    MyFunction = (pICFUNC)lpfnGetProcessID;
    26.  
    27.    /* The actual call to the function contained in the dll */
    28.    MyFunction(memDC);
    29.  
    30.    /* Release the Dll */
    31.    FreeLibrary(hGetProcIDDLL);
    32.  
    33.    /* The return val from the dll */
    34.     return 0;
    35. }
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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