Re: Error using P/Invoke with Winsock API using CF.NET
- From: "Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
- Date: Thu, 21 Jul 2005 10:30:57 -0700
You aren't going to be able to pass a callback function from managed code,
anyway, are you? It might be significantly easier to create a native DLL
with an exported function like: EstablishSSLConnection( SOCKET s ), after
setting up the socket in secure mode, etc. in managed code. The native
function would set the callback to another function in the DLL and then
return to managed code to allow the connection itself to be attempted.
You'd probably need a CleanupSSLConnection( SOCKET s ) call in the DLL,
also, to undo the callback setting.
Paul T.
"Stéphane" <Stphane@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E4CBAD7E-E623-4596-92B8-2C7105D9C853@xxxxxxxxxxxxxxxx
> I'm trying to enable SSL on my socket by following this article ->
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecomm5/html/wce50conImplementingaSecureSocket.asp?frame=true
>
> The only way to achieve this is to call ->
>
> public static extern int ioctlsocket(int s, uint controlCode, object
> inBuffer, int inBufferLen, byte[] outBuffer, int outBufferLen, out int
> outBytesWritten);
>
> I need to pass a Delegate for the certificate verification, and the
> current
> Socket.IOControl implementation does not allow that to occur.
>
> The CF.NET has a internal implementation of what I'm trying to access, so
> I
> know it "can" be done. It's located in System.Net.Sockets.SSLSOCK.
>
>
> Stéphane
>
>
> "Paul G. Tobey [eMVP]" wrote:
>
>> What exactly are you trying to accomplish? I don't think that you should
>> have to call ioctlsocket() directly; it should already be wrapped in the
>> ..NET CF socket class. That is, what's wrong with the existing
>> implementation that you can't use it?
>>
>> Paul T.
>>
>> "Stéphane" <Stphane@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:F9860587-A654-425E-A91C-B30674A3AE3B@xxxxxxxxxxxxxxxx
>> > Peter,
>> >
>> > I'm attempting to call ioctlsocket based from WINSOCK.H.
>> >
>> > WINSOCK.H has ioctlsocket defined as:
>> > int WINSOCKAPI ioctlsocket (SOCKET s, long cmd, u_long *argp);
>> >
>> > The native System.Net.Sockets.Socket.IOControl in CF.NET has:
>> >
>> > public int IOControl(int ioControlCode, byte[] optionInValue, byte[]
>> > optionOutValue);
>> >
>> > DllImport ->
>> > public static extern int ioctlsocket(int s, uint controlCode, byte[]
>> > inBuffer, int inBufferLen, byte[] outBuffer, int outBufferLen, out int
>> > outBytesWritten);
>> >
>> > but I need to pass different parameters to the ioctlsocket.
>> >
>> > DllImport ->
>> > public static extern int ioctlsocket(int s, uint controlCode, object
>> > inBuffer, int inBufferLen, byte[] outBuffer, int outBufferLen, out int
>> > outBytesWritten);
>> >
>> >
>> > Any thoughts, on another way?
>> >
>> > Stéphane
>> >
>> >
>> > "Peter Foot [MVP]" wrote:
>> >
>> >> Which particular winsock functions do you need? I've wrapped a few of
>> >> them
>> >> in the process of building the Bluetooth library
>> >> (www.peterfoot.net/Bluetoothv14.aspx)
>> >>
>> >> I believe that Sockets are the exception to the rule that Alex
>> >> described -
>> >> System.Net.Sockets wraps the Winsock APIs and the Handle exposed is
>> >> actually
>> >> a valid socket handle. What I think may be wrong in your case is your
>> >> P/Invoke definition - under XP you would use ws2_32.dll, under CE you
>> >> should
>> >> use "ws2.dll". As I said you may want to refer to some of the
>> >> P/Invokes
>> >> in
>> >> the Bluetooth library code, or post back with more details and I'll
>> >> try
>> >> and
>> >> help.
>> >>
>> >> Peter
>> >>
>> >> --
>> >> Peter Foot
>> >> Windows Embedded MVP
>> >> http://www.inthehand.com | http://www.peterfoot.net |
>> >> http://www.opennetcf.org
>> >>
>> >> "Stéphane" <Stéphane@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> >> news:B08090D3-DB13-497E-8550-2DA78D661D26@xxxxxxxxxxxxxxxx
>> >> >I need to call additional winsock functions that are not available
>> >> >through
>> >> > the .NET framework and planned to do so through P/Invoke calls.
>> >> >
>> >> > In theory using the System.Net.Sockets.Socket.Handle I should be
>> >> > able
>> >> > to
>> >> > then call external winsock functions. Unfortunately this does not
>> >> > seem
>> >> > to
>> >> > work from CF.NET. I can create a new socket using the winsock
>> >> > socket
>> >> > function, but I can't access an existing CF.NET socket with the
>> >> > winsock
>> >> > call
>> >> > using the Socket.Handle property.
>> >> >
>> >> > I am using the following DllImport statement to access the winsock
>> >> > calls.
>> >> >
>> >> > [DllImport("winsock.dll", SetLastError=true)]
>> >> >
>> >> > I can perform the exact same thing in C# in a Windows Application
>> >> > accessing
>> >> > the ws2_32.dll
>> >> >
>> >> > I can post more information if required. I was just wondering if
>> >> > there
>> >> > is
>> >> > a
>> >> > documented issue with calling native winsock P/Invoke functions from
>> >> > CF.NET
>> >> > before I kept banging my head against the wall.
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>
.
- Follow-Ups:
- Re: Error using P/Invoke with Winsock API using CF.NET
- From: Stéphane
- Re: Error using P/Invoke with Winsock API using CF.NET
- References:
- Error using P/Invoke with Winsock API using CF.NET
- From: Stéphane
- Re: Error using P/Invoke with Winsock API using CF.NET
- From: Peter Foot [MVP]
- Re: Error using P/Invoke with Winsock API using CF.NET
- From: Stéphane
- Re: Error using P/Invoke with Winsock API using CF.NET
- From: Paul G. Tobey [eMVP]
- Re: Error using P/Invoke with Winsock API using CF.NET
- From: Stéphane
- Error using P/Invoke with Winsock API using CF.NET
- Prev by Date: Re: Error using P/Invoke with Winsock API using CF.NET
- Next by Date: new questions about com control
- Previous by thread: Re: Error using P/Invoke with Winsock API using CF.NET
- Next by thread: Re: Error using P/Invoke with Winsock API using CF.NET
- Index(es):
Relevant Pages
|
Loading