Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting a buffer with StringCbPrintf
    text
    copied!<p>I am facing difficulty in how to format a buffer using StringCbPrintf, here what it should be an HTTP request:</p> <pre><code>char getExternalIpRequest[1200]; ZeroMemory(getExternalIpRequest, 1200); StringCbPrintf(getExternalIpRequest, 1200, "&lt;?xml version=\"1.0\"?&gt;" "&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"&gt;" "&lt;SOAP-ENV:Body&gt;" "&lt;m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\"&gt;" "&lt;NewRemoteHost xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"&gt;" "" "&lt;/NewRemoteHost&gt;" "&lt;NewExternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\"&gt;" "%s" "&lt;/NewExternalPort&gt;" "&lt;NewProtocol xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"&gt;" "%s" "&lt;/NewProtocol&gt;" "&lt;NewInternalPort xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui2\"&gt;" "%s" "&lt;/NewInternalPort&gt;" "&lt;NewInternalClient xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"&gt;" "%s" "&lt;/NewInternalClient&gt;" "&lt;NewEnabled xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"boolean\"&gt;" "1" "&lt;/NewEnabled&gt;" "&lt;NewPortMappingDescription xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"string\"&gt;" "%s" "&lt;/NewPortMappingDescription&gt;" "&lt;NewLeaseDuration xmlns:dt=\"urn:schemas-microsoft-com:datatypes\" dt:dt=\"ui4\"&gt;" "0" "&lt;/NewLeaseDuration&gt;" "&lt;/m:AddPortMapping&gt;" "&lt;/SOAP-ENV:Body&gt;" "&lt;/SOAP-ENV:Envelope&gt;\r\n\r\n", externalPort, protocol, internalPort, internalp, entryDescription); // externalPort, protocol, internalPort, internalp, entryDescription are **char*** type. char getExternalIpRequestHeader[1500]; ZeroMemory(getExternalIpRequestHeader, 1500); StringCbPrintf(getExternalIpRequestHeader, 1500, "POST /UD/?3 HTTP/1.1\r\n" "Content-Type: text/xml; charset=\"utf-8\"\r\n" "SOAPAction: \"urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress\"\r\n" "User-Agent: Mozilla/4.0 (compatible; UPnP/1.0; Windows 9x)\r\n" "Host: %s\r\n" "Content-Length: %s\r\n" "Connection: Keep-Alive\r\n" "Cache-Control: no-cache\r\n" "Pragma: no-cache\r\n\r\n", upnpDeviceIp, strlen(getExternalIpRequest)); </code></pre> <p>But when I echo it in console I receive access violation message.</p> <p><strong>UPDATE</strong> I noticed if I comment one of StringCbPrintf(getExternalIpRequest) or StringCbPrintf(getExternalIpRequestHeader) there will e no crash.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload