/[gpgoe]/trunk/src/OEMisc.c
ViewVC logotype

Diff of /trunk/src/OEMisc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by twoaday, Mon Mar 27 12:47:50 2006 UTC revision 12 by twoaday, Fri Apr 7 10:46:41 2006 UTC
# Line 30  Line 30 
30  #include "GPGOE.h"  #include "GPGOE.h"
31    
32    
33    char*
34    native_to_utf8 (const char *string)
35    {
36        wchar_t *result;
37        char *native;
38        int n;
39    
40        n = MultiByteToWideChar (GetACP (), 0, string, -1, NULL, 0);
41        if (n < 0)
42            return NULL;
43    
44        result = (wchar_t*)xcalloc (1, (n+1) * sizeof *result);
45    
46        n = MultiByteToWideChar (GetACP (), 0, string, -1, result, n);
47        if (n < 0) {
48            free (result);
49            return NULL;
50        }
51    
52        n = WideCharToMultiByte (CP_UTF8, 0, result, -1, NULL, 0, NULL, NULL);
53        if (n < 0)
54            return NULL;
55    
56        native = (char*)xcalloc (1, n+1);
57    
58        n = WideCharToMultiByte (CP_UTF8, 0, result, -1, native, n, NULL, NULL);
59        if (n < 0) {
60            free (result);
61            return NULL;
62        }
63    
64        free (result);
65        return native;
66    }
67    
68    
69  /* Convert the UTF8 string @string into the native charset. */  /* Convert the UTF8 string @string into the native charset. */
70  char*  char*
71  utf8_to_native (const char *string)  utf8_to_native (const char *string)
# Line 108  int Line 144  int
144  set_clip_text (HWND hwnd, const char *text, int nbytes)  set_clip_text (HWND hwnd, const char *text, int nbytes)
145  {      {    
146      HANDLE clipmem;      HANDLE clipmem;
     int rc = 0;  
147      char *p;      char *p;
148            
149      if (OpenClipboard (hwnd) == FALSE)        if (OpenClipboard (hwnd) == FALSE)  
# Line 120  set_clip_text (HWND hwnd, const char *te Line 155  set_clip_text (HWND hwnd, const char *te
155          abort ();          abort ();
156      p = (char *) GlobalLock (clipmem);      p = (char *) GlobalLock (clipmem);
157      if (p == NULL) {      if (p == NULL) {
158          rc = -1;          CloseClipboard ();
159          goto leave;              GlobalFree (clipmem);
160            return -1;
161      }      }
162      memcpy (p, text, nbytes);      memcpy (p, text, nbytes);
163      p[nbytes] = '\0';      p[nbytes] = '\0';
164            
     GlobalUnlock (clipmem);  
165      SetClipboardData (CF_TEXT, clipmem);      SetClipboardData (CF_TEXT, clipmem);
166        GlobalUnlock (clipmem);
167        CloseClipboard ();
168      GlobalFree (clipmem);      GlobalFree (clipmem);
169            
 leave:  
     CloseClipboard ();  
170      return 0;      return 0;
171  }  }
172    
# Line 158  xstrdup (const char *s) Line 193  xstrdup (const char *s)
193  }  }
194    
195    
196    void
197    xfree (void *p)
198    {
199        if (p != NULL)
200            free (p);
201    }
202    
203    
204  /* printf style message box. */  /* printf style message box. */
205  void  void
206  show_error (HWND hwnd, const char *caption, UINT type, const char *fmt, ...)  show_error (HWND hwnd, const char *caption, UINT type, const char *fmt, ...)

Legend:
Removed from v.11  
changed lines
  Added in v.12

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26