[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A Win32API question

Ben

4/18/2006 8:29:00 PM

Hi, I copied a dll from a matlab sample. (matlab uses this DLL to demo
its dll loading function). one of the functions in this DLL is
stringToUpper which has the prototype

EXPORTED_FUNCTION char* stringToUpper(char *);

For the arguments in Win32API.new, I assumed the 3rd arg is the input
type, so tried 'S' as string. 'L' is the return type as long. Not sure
if I need to use 'S' instead.

If a function has 3 parameters, do I need to write ['S', 'L', 'F'] for
string, integer, float inputs?

=========================================
irb(main):001:0> require 'Win32API'
=> true
irb(main):002:0> aa =
Win32API.new("shrlibsample.dll","stringToUpper",['S'],'L' )
RuntimeError: LoadLibrary: shrlibsample.dll

from (irb):2:in `initialize'
from (irb):2
irb(main):003:0>
==========================================

Any comments are welcome.

6 Answers

Daniel Berger

4/18/2006 9:07:00 PM

0

Ben wrote:
> Hi, I copied a dll from a matlab sample. (matlab uses this DLL to demo
> its dll loading function). one of the functions in this DLL is
> stringToUpper which has the prototype
>
> EXPORTED_FUNCTION char* stringToUpper(char *);

What does this do that String#upcase doesn't? Just curious.

> For the arguments in Win32API.new, I assumed the 3rd arg is the input
> type, so tried 'S' as string. 'L' is the return type as long. Not sure
> if I need to use 'S' instead.

Eh? What 3rd argument? Looks like it has one argument to me, a char
pointer, which is represented by a 'P'.

> If a function has 3 parameters, do I need to write ['S', 'L', 'F'] for
> string, integer, float inputs?

A string is a char pointer, thus it's represented by a 'P'. For a
float just use 'L'.

> =========================================
> irb(main):001:0> require 'Win32API'
> => true
> irb(main):002:0> aa =
> Win32API.new("shrlibsample.dll","stringToUpper",['S'],'L' )
> RuntimeError: LoadLibrary: shrlibsample.dll
>
> from (irb):2:in `initialize'
> from (irb):2
> irb(main):003:0>
> ==========================================

There are a few possibilities here. The first thing to check is that
your dll file is named properly and is in your dll load path. The next
thing to check is that your function is, in fact, exported and that
you've matched the case exactly. The last thing you'll want to do is
correct the prototype to 'P' (although that won't cause the
RuntimeError at this point).

Hope that helps.

Dan

Ben

4/18/2006 9:57:00 PM

0

Thank you very much for your help.

This is a toy function which converts 'abcde' to 'ABCDE'.

Checked the export name with dumpbin. I have the C source and header
files also. Thus, DLL filename and function name are correct.

Modified 'S' to 'P'. But the same error appears:

====================================================
irb(main):004:0> aa =
Win32API.new("shrlibsample.dll","stringToUpper",['P'],'L')
RuntimeError: LoadLibrary: shrlibsample.dll

from (irb):4:in `initialize'
from (irb):4
from :0
====================================================


I am missing C and Fortran now. I hate to sit there and have no clue to
modify even a single letter.

Daniel Berger

4/18/2006 11:54:00 PM

0

Ben wrote:
> Thank you very much for your help.
>
> This is a toy function which converts 'abcde' to 'ABCDE'.
>
> Checked the export name with dumpbin. I have the C source and header
> files also. Thus, DLL filename and function name are correct.
>
> Modified 'S' to 'P'. But the same error appears:
>
> ====================================================
> irb(main):004:0> aa =
> Win32API.new("shrlibsample.dll","stringToUpper",['P'],'L')
> RuntimeError: LoadLibrary: shrlibsample.dll
>
> from (irb):4:in `initialize'
> from (irb):4
> from :0
> ====================================================
>
>
> I am missing C and Fortran now. I hate to sit there and have no clue to
> modify even a single letter.

This is your clue:

RuntimeError: LoadLibrary: shrlibsample.dll

Behind the scenes Win32API.new is just calling LoadLibrary() +
GetProcAddress(). What you can see from this error message is that
LoadLibrary() is failing. That tells me the most likely culprit is
your load path.

In any case, you can specify a full path the to .dll file in the first
argument:

Win32API.new("C:\\path\\to\\shrlibsample.dll", "stringToUpper", 'P',
'P')

The 3rd argument can be either an array of characters or a simple
string - either way is fine. The final argument should be a 'P' as
well since the function returns a char pointer.

Regards,

Dan

Ben

4/19/2006 3:49:00 PM

0

Many thanks for your patience and help. I've learnt a lot from your
replies. The Win32API docs are too skinnie.

This becomes a two-line puzzle to me. Do I need to pick another DLL? I
can load this DLL under Matlab.
=====================================
D:\shrlib>irb
irb(main):001:0> require 'Win32API'
=> true
irb(main):002:0> aa =
Win32API.new("D:\\shrlib\\shrlibsample.dll","stringToUpper",'P','P')
RuntimeError: LoadLibrary: D:\shrlib\shrlibsample.dll

from (irb):2:in `initialize'
from (irb):2
irb(main):003:0>
==============================================

Ben

Fred J. McCall

4/9/2011 11:50:00 PM

0

Malcolm <Malcolm@indaal.demon.co.uk> wrote:

>
>In article
><c1207799-719c-495d-9898-47510467c19e@k7g2000yqj.googlegroups.com>,
>Akins of that Ilk <the_akins_of_akins@yahoo.com> writes
>>
>>My knowelge of women comes from first hand experience,
>
>You're a woman???!!!
>

No, he just has the testicles of one...

--
You are
What you do
When it counts.

Akins of that Ilk

4/10/2011 12:13:00 AM

0

On Apr 9, 6:35 pm, Fred J. McCall <fjmcc...@gmail.com> wrote:
> Akins of that Ilk <the_akins_of_ak...@yahoo.com> wrote:
>
>
>
>
>
> >On Apr 9, 12:57 pm, Fred J. McCall <fjmcc...@gmail.com> wrote:
> >> Akins of that Ilk <the_akins_of_ak...@yahoo.com> wrote:
>
> >> >On Apr 9, 12:36 pm, Fred J. McCall <fjmcc...@gmail.com> wrote:
> >> >> Akins of that Ilk <the_akins_of_ak...@yahoo.com> wrote:
>
> >> >> >Why pussy-foot around like you sissy liberals? I believe in calling a
> >> >> >spade a spade. Tell it like it is. The female personality is a
> >> >> >constant whirlwind of hormone-induced emotional disharmony.
>
> >> >> While, as we all know, men don't have any hormones at all.
>
> >> >Not the sort that regularly cause them to burst into tears at the drop
> >> >of a hat, or that make the go on impulsive spending sprees for high-
> >> >heeled shoes and designer handbags, or that cause them to have binge-
> >> >type cravings for sweets, or cause them to become bewildered while
> >> >driving in traffic.....
>
> >> Poor, stupid Akins. And so we see that your knowledge of women is
> >> only surpassed by your racial tolerance.
>
> >> Women don't have those hormones, either (there's a 'buy shoes'
> >> hormone?). And if they did, none of those sound particularly
> >> dangerous as the national level.
>
> >> Meanwhile, men have hormones that make them become aggressive and get
> >> into fights. Given the choice between a President with 'hormones'
> >> that cause eating chocolate and a President with 'hormones' that cause
> >> eating Czechoslovakia, I think I know which one sane people ought to
> >> choose...
>
> >My knowelge of women comes from first hand experience, not just from
> >theory as in your case, Fred.
>
> You want to know how to make a hormone, Akins?
>
> Ask your wife what I did during my last visit.

During your last visit to the psychiatrist.....