adddsn.c
Go to the documentation of this file.
1
14#ifndef _WIN32
15#error "only WIN32 supported"
16#endif
17#include <windows.h>
18#include <sql.h>
19#include <sqlext.h>
20#include <odbcinst.h>
21#include <winver.h>
22#include <string.h>
23#include <ctype.h>
24#include <stdio.h>
25
31static BOOL
33{
34 WORD err = 1;
35 DWORD code;
36 char errmsg[301];
37 WORD errlen, errmax = sizeof (errmsg) - 1;
38 int rc;
39 BOOL ret = FALSE;
40
41 do {
42 errmsg[0] = '\0';
43 rc = SQLInstallerError(err, &code, errmsg, errmax, &errlen);
44 if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
45 MessageBox(NULL, errmsg, name,
46 MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
47 ret = TRUE;
48 }
49 err++;
50 } while (rc != SQL_NO_DATA);
51 return ret;
52}
53
65int APIENTRY
66WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
67 LPSTR lpszCmdLine, int nCmdShow)
68{
69 char tmp[1024], *p, *drv, *cfg, *msg;
70 int i, op;
71
72 GetModuleFileName(NULL, tmp, sizeof (tmp));
73 p = tmp;
74 while (*p) {
75 *p = tolower(*p);
76 ++p;
77 }
78 p = strrchr(tmp, '\\');
79 if (p == NULL) {
80 p = tmp;
81 }
82 op = ODBC_ADD_DSN;
83 msg = "Adding DSN";
84 if (strstr(p, "rem") != NULL) {
85 msg = "Removing DSN";
86 op = ODBC_REMOVE_DSN;
87 }
88 if (strstr(p, "sys") != NULL) {
89 if (op == ODBC_REMOVE_DSN) {
90 op = ODBC_REMOVE_SYS_DSN;
91 } else {
92 op = ODBC_ADD_SYS_DSN;
93 }
94 }
95 strncpy(tmp, lpszCmdLine, sizeof (tmp));
96 /* get driver argument */
97 i = strspn(tmp, "\"");
98 drv = tmp + i;
99 if (i > 0) {
100 i = strcspn(drv, "\"");
101 drv[i] = '\0';
102 cfg = drv + i + 1;
103 } else {
104 i = strcspn(drv, " \t");
105 if (i > 0) {
106 drv[i] = '\0';
107 cfg = drv + i + 1;
108 } else {
109 cfg = "\0\0";
110 }
111 }
112 if (strlen(drv) == 0) {
113 MessageBox(NULL, "No driver name given", msg,
114 MB_ICONERROR|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
115 exit(1);
116 }
117 i = strspn(cfg, " \t;");
118 cfg += i;
119 i = strlen(cfg);
120 cfg[i + 1] = '\0';
121 if (i > 0) {
122 p = cfg;
123 do {
124 p = strchr(p, ';');
125 if (p != NULL) {
126 p[0] = '\0';
127 p += 1;
128 }
129 } while (p != NULL);
130 }
131 p = cfg;
132 if (SQLConfigDataSource(NULL, (WORD) op, drv, cfg)) {
133 exit(0);
134 }
136 exit(1);
137}
138
static BOOL ProcessErrorMessages(char *name)
Handler for ODBC installation error messages.
Definition adddsn.c:32
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Main function of DSN utility.
Definition adddsn.c:66

Generated on Sun Nov 26 2023 by doxygen.
Contact: chw@ch-werner.de