To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Other Languages > C and C++

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old May 29th, 2007, 04:31 AM   #1
iPrank
PoorPoster
 
iPrank's Avatar
 
Join Date: Oct 05
Location: in an island
Posts: 2,654
iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)
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.     long lb, pa;
  4.     //map 'user32' into the address space of the calling process.
  5.     lb = LoadLibrary("Project1.dll");
  6.     //retrieve the address of 'SetWindowTextA'
  7.     pa =  GetProcAddress(lb, "WinAmpVisTest");
  8.     // HOW TO CALL THE FOLLOWING PROCEDURE FROM MY DLL ?
  9.     //Public Sub WinAmpVisTest(MemDC As Long, this_mod As WinAMPVisModule)
  10.     //unmap the library's address
  11.     FreeLibrary (lb);
  12.     return 0;
  13. }

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.     Description  As String   'description of module
  3.     hWndParent   As Long         'parent window (filled in by calling app)
  4.     hDLLInstance As Long         'instance handle to DLL (filled this in)
  5.     sRate        As Long         'sample rate (filled in by calling app)
  6.     nCh          As Long         'number of channels (filled in...)
  7.     LatencyMs    As Long         'latency from call of RenderFrame to actual drawing
  8.     '(calling app looks at this value when getting data)
  9.     DelayMs      As Long         'delay between calls in ms
  10.     'the data is filled in according to the respective Nch entry
  11.     SpectrumNch As Long
  12.     WaveformNch As Long
  13.     SpectrumData(0 To 575, 0 To 1) As Byte
  14.     WaveformData(0 To 575, 0 To 1) As Byte
  15.     'These function pointers all get passed one argument -- a pointer to a
  16.     'winampVisModule struct (type).
  17.     ConfigFP As Long        'configuration dialog function -- returns void
  18.     InitFP As Long          '0 on success, creates window, etc. -- returns int
  19.     RenderFP As Long        '0 on success, 1 if vis should end -- returns int
  20.     QuitFP As Long          'call when done
  21.     UserDataP As Long       'user data, optional
  22. 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 04:38 AM.
iPrank is offline   Reply With Quote
Old May 29th, 2007, 06:49 AM   #2
learning c
Banned
 
learning c's Avatar
 
Join Date: Mar 07
Location: canberra (australia's capital)
Posts: 198
learning c has a little shameful behaviour in the past
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?
learning c is offline   Reply With Quote
Old May 29th, 2007, 07:16 AM   #3
iPrank
PoorPoster
 
iPrank's Avatar
 
Join Date: Oct 05
Location: in an island
Posts: 2,654
iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)iPrank is a glorious beacon of light (400+)
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.    /* get pointer to the function in the dll*/
  7.    FARPROC lpfnGetProcessID = GetProcAddress((HMODULE)hGetProcIDDLL, "WinAmpVisTest");
  8.    /*
  9.     Define the Function in the DLL for reuse. This is just prototyping
  10.     the dll's function. A mock of it. Use "stdcall" for maximum
  11.     compatibility.
  12.    */
  13. typedef int (__stdcall * pICFUNC)(HDC);
  14.    pICFUNC MyFunction;
  15.    
  16.     if (hGetProcIDDLL==NULL)
  17.     {
  18.         TextOut(memDC, 0,0, "Can not open the Library",24);
  19.         return 0;
  20.     }
  21.    MyFunction = (pICFUNC)lpfnGetProcessID;
  22.    /* The actual call to the function contained in the dll */
  23.    MyFunction(memDC);
  24.    /* Release the Dll */
  25.    FreeLibrary(hGetProcIDDLL);
  26.    /* The return val from the dll */
  27.     return 0;
  28. }
iPrank is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > C and C++


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:42 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.