Vb6 Convert

  • Thread starter Thread starter Phil Hunt
  • Start date Start date
P

Phil Hunt

Hi
Can you help me with converting a VB6 Declare Function construct to C#
systax. I think it is in the form of

[DLLImport ("A.DLL")]
public extrn void someFunction(.....);

But I don't see the association between the 2 statements. Can someone
explain ?

THanks
 
Phil,

Well, the DllImport attribute tells the CLR what the name of the DLL is
to load to find the function in (as well as other information, like the .
The CLR will then use function information to figure out the signature of
the function and load it from the dll, and subsequently call it.

The "extern" keyword here, combined with the attribute indicates that
the function is found in an unmanaged DLL (there should be a static keyword
here as well).
 
The dll i have that has many entry point. It seems like I have to repeat the
Import statement everytime I declare a different function. Is that a short
hand for that. Also in VB6 the Declare stmt associate the fucntion with the
dll. Can I do that in this contruct ?

Thanks again


Nicholas Paldino said:
Phil,

Well, the DllImport attribute tells the CLR what the name of the DLL is
to load to find the function in (as well as other information, like the .
The CLR will then use function information to figure out the signature of
the function and load it from the dll, and subsequently call it.

The "extern" keyword here, combined with the attribute indicates that
the function is found in an unmanaged DLL (there should be a static
keyword here as well).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Phil Hunt said:
Hi
Can you help me with converting a VB6 Declare Function construct to C#
systax. I think it is in the form of

[DLLImport ("A.DLL")]
public extrn void someFunction(.....);

But I don't see the association between the 2 statements. Can someone
explain ?

THanks
 
Phil,

Yes, you are right, you have to make a new declaration for each function
that you want to use through the P/Invoke layer.

There is no shorthand for that, AFAIK.

The DllImport attribute is what associates the function declaration with
the DLL that it is located in. You have to repeat this for every
declaration as well.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Phil Hunt said:
The dll i have that has many entry point. It seems like I have to repeat
the Import statement everytime I declare a different function. Is that a
short hand for that. Also in VB6 the Declare stmt associate the fucntion
with the dll. Can I do that in this contruct ?

Thanks again


Nicholas Paldino said:
Phil,

Well, the DllImport attribute tells the CLR what the name of the DLL
is to load to find the function in (as well as other information, like
the . The CLR will then use function information to figure out the
signature of the function and load it from the dll, and subsequently call
it.

The "extern" keyword here, combined with the attribute indicates that
the function is found in an unmanaged DLL (there should be a static
keyword here as well).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Phil Hunt said:
Hi
Can you help me with converting a VB6 Declare Function construct to C#
systax. I think it is in the form of

[DLLImport ("A.DLL")]
public extrn void someFunction(.....);

But I don't see the association between the 2 statements. Can someone
explain ?

THanks
 
Thanks for your help.

Nicholas Paldino said:
Phil,

Yes, you are right, you have to make a new declaration for each
function that you want to use through the P/Invoke layer.

There is no shorthand for that, AFAIK.

The DllImport attribute is what associates the function declaration
with the DLL that it is located in. You have to repeat this for every
declaration as well.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Phil Hunt said:
The dll i have that has many entry point. It seems like I have to repeat
the Import statement everytime I declare a different function. Is that a
short hand for that. Also in VB6 the Declare stmt associate the fucntion
with the dll. Can I do that in this contruct ?

Thanks again


Nicholas Paldino said:
Phil,

Well, the DllImport attribute tells the CLR what the name of the DLL
is to load to find the function in (as well as other information, like
the . The CLR will then use function information to figure out the
signature of the function and load it from the dll, and subsequently
call it.

The "extern" keyword here, combined with the attribute indicates that
the function is found in an unmanaged DLL (there should be a static
keyword here as well).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi
Can you help me with converting a VB6 Declare Function construct to C#
systax. I think it is in the form of

[DLLImport ("A.DLL")]
public extrn void someFunction(.....);

But I don't see the association between the 2 statements. Can someone
explain ?

THanks
 
Back
Top