|
|||||||
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Fanatic Member
Join Date: Jun 99
Location: California, USA
Posts: 659
![]() |
I'm getting this exception when I try to get the address of a function in a dll written in vc++ 6.0. The dll is a compiled winamp plugin and I can't change the plugin source.
Code:
System.Runtime.InteropServices.MarshalDirectiveException was unhandled
Message="Method's type signature is not PInvoke compatible."
Source="Winamp Plugin Host"
StackTrace:
at Winamp_Plugin_Host.OutputPlugin.GetProcAddress(Int32 hModule, String& lpProcName)
at Winamp_Plugin_Host.OutputPlugin..ctor(String FromFile) in C:\Documents and Settings\Jack Schitt\Desktop\design\programming\Winamp Plugin Host\PluginClasses.vb:line 76
Code:
__declspec( dllexport ) Out_Module * winampGetOutModule() |
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [2005] PInvoke on a function declared with __declspec
VB Code:
|
|
|
|
|
|
#3 | |
|
Fanatic Member
Join Date: Jun 99
Location: California, USA
Posts: 659
![]() |
Re: [2005] PInvoke on a function declared with __declspec
Quote:
Can this be done with either DllImport or Declare? |
|
|
|
|
|
|
#4 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: [2005] PInvoke on a function declared with __declspec
|
|
|
|
|
|
#5 | |
|
Fanatic Member
Join Date: Jun 99
Location: California, USA
Posts: 659
![]() |
Re: [2005] PInvoke on a function declared with __declspec
Quote:
It looks a little complicated for what I'm trying to do and seems to apply to .Net 1.x. I'm including the unfinished class I'm working on. If you have winamp, create a new instance of the class and provide the full path to any dll file in the plugins folder of winamp who's filename begins with "OUT". The test in this case would be to run the About method of the class and see if you get an 'About This Plugin...' type window. I haven't been able to test any of the delegates in the OutModule structure as the problem I'm having occures before this is returned. You can get winamp free at winamp.com. The sdk is available free at http://www.winamp.com/nsdn/winamp/sdk/index.php VB Code:
|
|
|
|
|
|
|
#6 |
|
Fanatic Member
Join Date: Jun 99
Location: California, USA
Posts: 659
![]() |
Re: [2005] PInvoke on a function declared with __declspec
Not for the faint at heart...
I took my previous code and added a dynamic binder as suggested by penagate. Everything, including the dynamic binding works un until the point where it calls the function in the dll. Then I get the same exception (signature not PInvoke compatible). This is the entire contents of the plugin file... (The exception occurs on the bolded line near the bottom) The second code section is the function template I'm using. This file should have its build action set to none. Additionally, add it as a resource via the resource manager. The resource should be named 'Template' WinampPluginClasses.vb VB Code:
Template.vb VB Code:
|
|
|
|
|
|
#7 |
|
Fanatic Member
Join Date: Jun 99
Location: California, USA
Posts: 659
![]() |
Re: [2005] PInvoke on a function declared with __declspec
Looks like I got it working. I'll post the working code after optimizing it a bit. I knew dynamically compiling code was a little overkill. I'm switching it back to LoadLibrary, GetProcAddress, and FreeLibrary.
The problem was that (apparently) you can't PInvoke something if the return value isn't something standard (i.e. a number or a boolean.) Now, I simply take the number returned and use that as the first param of Marshal.PtrToStructure Now the test works properly and it looks like I don't need to compile code from my program. (If you found this post by doing a search for compiling code or executing scripts from your app, the above source code does do that, btw) |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|