CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2010
    Posts
    75

    Write 'C' char array[] to VB array() As Char

    Hi VB Experts

    Is it possible for a 'C' function to use a pointer to a char array to write to a VB array As Char?

    I have tried this but the C function only fills the first element in the VB array.

    C Code:
    Code:
    EXPORT int __stdcall SocknetRecv (int nSocket, LPSTR *lpBuf, int nSize)
    {
    	int nRecv, nLen;
    	LPTSTR lpPtr;
    
    	for (nLen = nSize, lpPtr = *lpBuf; nLen > 0;)
    	{
    		nRecv = recv(nSocket, lpPtr, nLen, 0);
    		if (nRecv <= 0)
    		{
    			nResult = WSAGetLastError();
    			return nRecv;
    		}
    
    		lpPtr += nRecv;
    		nLen -= nRecv;
    	}
    
    	nResult = 0;
    
    	return nSize - nLen;
    }
    And in VB
    Code:
    Public Declare Function SocknetRecv Lib "SocknetLib.dll" (ByVal nSocket As Integer, ByRef Buffer() As Char, ByVal Size As Integer) As Integer
    
    Dim RData(100) As Char
    'Call it
    nBytes = SocknetRecv(Socket, RData, RData.Length)
    If anyone can help me with this i will be most grateful, I do not know VB very well

    Looking forward to your replies
    Last edited by RipRage; April 17th, 2012 at 12:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured