summaryrefslogtreecommitdiffstats
path: root/util/src/platforms/windows/axutil_windows.c
blob: e2abb5df43f17017d4ce11550e14e5188e1c9b01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <windows/axutil_windows.h>
#include <stdio.h>


/*

std::string* getPlatformErrorMessage(long errorNumber)
{
   std::string* returningString = new std::string();
    LPVOID lpMsgBuf;

   FormatMessage(
   FORMAT_MESSAGE_ALLOCATE_BUFFER |
   FORMAT_MESSAGE_FROM_SYSTEM,
   NULL,
   errorNumber,
   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   (LPTSTR) &lpMsgBuf,
   0, NULL );

   returningString->append((LPTSTR)lpMsgBuf);
    LocalFree(lpMsgBuf);

    return returningString;
}
 */
AXIS2_EXTERN HMODULE AXIS2_CALL
callLoadLib(
    char *lib)
{
    /* Disable display of the critical-error-handler message box */
    SetErrorMode(SEM_FAILCRITICALERRORS);
    return LoadLibraryEx(lib, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
}

AXIS2_EXTERN struct tm *AXIS2_CALL
axis2_win_gmtime(
    const time_t * timep,
    struct tm *result)
{
    return gmtime(timep);
}

AXIS2_EXTERN void AXIS2_CALL
axutil_win32_get_last_error(
    axis2_char_t *buf,
    unsigned int buf_size)
{
    LPVOID lpMsgBuf;
    int rc = GetLastError();
    sprintf(buf, "DLL Load Error %d: ", rc);
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, 0,
        (LPTSTR) & lpMsgBuf, 0, NULL);
    if(lpMsgBuf)
    {
        strncat(buf, (char*)lpMsgBuf, buf_size - strlen(buf) - 1);
    }
    LocalFree(lpMsgBuf);
}

AXIS2_EXTERN void AXIS2_CALL
axutil_win32_get_last_wsa_error(
    axis2_char_t *buf,
    unsigned int buf_size)
{
    LPVOID lpMsgBuf;
    int rc = WSAGetLastError();
    sprintf(buf, "Winsock error %d: ", rc);
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, 0,
        (LPTSTR) & lpMsgBuf, 0, NULL);
    if(lpMsgBuf)
    {
        strncat(buf, (char*)lpMsgBuf, buf_size - strlen(buf) - 1);
    }
    LocalFree(lpMsgBuf);
}