Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Convert C++ code to python

Convert C++ code to python

Scheduled Pinned Locked Moved C / C++ / MFC
c++pythonsysadminjsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megha Bhamare
    wrote on last edited by
    #1

    Hi

    Can any one help me convert the C++ code to python

    char buf[1024];
    int nBufLen1;

    CString sendBuffer("$Magic $Command AudienceCount 0 10000");
    //int nBufLen1 = sendBuffer.GetLength();
    buf\[0\] = 0;
    buf\[1\] = 0;
    WORD len = sendBuffer.GetLength() \* 2;
    nBufLen1 = len + 5;  // length of message
    
    buf\[2\] = (BYTE)len;
    char \*pStr = T2A(sendBuffer);
    strncpy(&buf\[3\],pStr,len);    // actual string to send
    
    buf\[len + 3\] = 0;
    buf\[len + 4\] = 0;
    
    
    if(sock.Send (&buf,nBufLen1) != nBufLen1)
    {
    	OutputDebugString(L"Socket Send Failed");
    	return FALSE;
    }
    

    I have a MFC C++ server(with CArchive) (serialization used) to which I need to send the data over socket.
    The above code works in C++ client, need to replicate same in python so that it might work.

    What I have tried:

    I have been trying to use seasnake, but unable to install using pip.
    A few online converter are also there, but many are not working.

    L 1 Reply Last reply
    0
    • M Megha Bhamare

      Hi

      Can any one help me convert the C++ code to python

      char buf[1024];
      int nBufLen1;

      CString sendBuffer("$Magic $Command AudienceCount 0 10000");
      //int nBufLen1 = sendBuffer.GetLength();
      buf\[0\] = 0;
      buf\[1\] = 0;
      WORD len = sendBuffer.GetLength() \* 2;
      nBufLen1 = len + 5;  // length of message
      
      buf\[2\] = (BYTE)len;
      char \*pStr = T2A(sendBuffer);
      strncpy(&buf\[3\],pStr,len);    // actual string to send
      
      buf\[len + 3\] = 0;
      buf\[len + 4\] = 0;
      
      
      if(sock.Send (&buf,nBufLen1) != nBufLen1)
      {
      	OutputDebugString(L"Socket Send Failed");
      	return FALSE;
      }
      

      I have a MFC C++ server(with CArchive) (serialization used) to which I need to send the data over socket.
      The above code works in C++ client, need to replicate same in python so that it might work.

      What I have tried:

      I have been trying to use seasnake, but unable to install using pip.
      A few online converter are also there, but many are not working.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See 21. Internet Protocols and Support — Python 3.3.7 documentation[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups