Re: Error using P/Invoke with Winsock API using CF.NET



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.
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>


.



Relevant Pages

  • Re: Integrating with legacy code
    ... Removed nochkclr.obj as a linker input ... Extention DLL. ... access them from within the web service, ... >order to add managed code to it: ...
    (microsoft.public.dotnet.general)
  • Re: Strange file not found exception
    ... Assemblies *must* reside in same directory. ... DLL on Windows Server 2003 x64 using PIA interop. ... I find creating a COM coclass object in managed code is ok, ...
    (microsoft.public.vc.language)
  • Dependency walker msvcr80d.dll missing coredll.dll and dwmapi.dll
    ... I've completed migrating one of our company's C++ Managed Code ... The dll is written in MFC with sections of C++ ... The dll exports its objects in the same manner as any VS2005 Solution Wizard ... In fact when I peer into the dll with the DepedencyWalker app, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Pinvoke help
    ... you say you put the dll one directory down from where the .sln ... public static extern int StartCamera; ... MouseButtons button, Int32 clicks) ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: connect() call blocks forever
    ... It turns out that another thread had loaded a new DLL. ... > Gist of the code is: get a new socket, set some socket options, call ... > WSAEventSelect on the socket with an event and FD_CONNECT. ... I have no idea what its waiting on. ...
    (microsoft.public.win32.programmer.networks)

Loading