News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

API similar to urlencode ?

Started by Faiseur, September 26, 2008, 01:13:30 PM

Previous topic - Next topic

Faiseur

Hello everyone.

One of my programs must interact with scripts php or cgi via the Internet. I'm looking for a function usable in Masm similar to "urlencode" in php (see http://www.albionresearch.com/misc/urlencode.php). I must convert special characters to use it in Url (p. ex: ä = %C3%A4, ö = %C3%B6, etc ). There must be a Windows API that deals with this conversion but I have not yet found. Unfortunately I did not have Microsoft SDK installed on my computer.

If anyone can help me I thank him,

Faiseur
French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/

jj2007

Quote from: Faiseur on September 26, 2008, 01:13:30 PM
There must be a Windows API that deals with this conversion

Maybe the .net httputility.urlencode - but translating that to Masm might not be straightforward.

akane

Check the InternetCreateUrl function:
string url;
DWORD buflen = 256;

URL_COMPONENTS uc;
uc.dwStructSize      = sizeof(uc);
uc.lpszScheme        = NULL;
uc.dwSchemeLength    = 0;
uc.nScheme           = INTERNET_SCHEME_HTTP;
uc.lpszHostName      = "some.corporation.com";
uc.dwHostNameLength  = strlen(uc.lpszHostName);
uc.nPort             = INTERNET_DEFAULT_HTTP_PORT;
uc.lpszUserName      = NULL;
uc.dwUserNameLength  = 0;
uc.lpszPassword      = NULL;
uc.dwPasswordLength  = 0;
uc.lpszUrlPath       = "äąłć3.6=#%^&*";
uc.dwUrlPathLength   = strlen(uc.lpszUrlPath);
uc.lpszExtraInfo     = NULL;
uc.dwExtraInfoLength = 0;

InternetCreateUrl(&uc, ICU_ESCAPE, url, &buflen);
// url is now http://some.corporation.com/%E4%B9%B3%E63.6=%23%25%5E&*

Faiseur

Thanks jj2007 and akane.

InternetCreateUrl function fine. It is identical to urlencode. But strangely it is not the same protocol used in the language "script" with whom I interact. I will have to find a more complicated solution to my problem  :(

Ok, for information, this is a simple test in Masm for InternetCreateUrl.


   
      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      include \masm32\include\wininet.inc
      include \masm32\include\masm32.inc

      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
      includelib \masm32\lib\wininet.lib
      includelib \masm32\lib\masm32.lib

      include \masm32\macros\macros.asm

; #########################################################################

    .data

    Urllen          dd 512
    Hostname        db "some.corporation.com",0
    Urlpath         db "äaëç3.6=#%^&*",0
   
    .data?

    Urlc            URL_COMPONENTS <?>
    Url             db 512 dup(?)
 
    .code

start:   
    mov Urlc.nScheme,INTERNET_SCHEME_HTTP
    mov Urlc.lpszHostName,offset Hostname
    mov Urlc.dwHostNameLength,FUNC (szLen,addr Hostname)
    mov Urlc.nPort,INTERNET_DEFAULT_HTTP_PORT
    mov Urlc.lpszUrlPath,offset Urlpath
    mov Urlc.dwUrlPathLength,FUNC (szLen,addr Urlpath)
    mov Urlc.dwStructSize,sizeof Urlc

    invoke InternetCreateUrl,addr Urlc,ICU_ESCAPE,addr Url,addr Urllen

    fn MessageBox,0,addr Url,"Result",0

    invoke ExitProcess,0
end start

French asm Forum: http://www.asmforum.net/   Website: http://www.faiseur.net/