简体   繁体   English

如何从自定义 ODBC 驱动程序创建 DSN?

[英]How to create DSN from custom ODBC Driver?

For the last couple of weeks I'm struggling with ODBC in general.在过去的几周里,我一般都在为 ODBC 苦苦挣扎。 Made some progress but now I am stuck in setting up a dsn with custom ODBC driver.取得了一些进展,但现在我坚持使用自定义 ODBC 驱动程序设置 dsn。

What I understood, looking through postgres open source code.我的理解是,查看 postgres 开源代码。 I need to make a dll that contains two functions 1.ConfigDsn 2ConfigDriver我需要制作一个包含两个函数的dll 1.ConfigDsn 2ConfigDriver

Here is example of my code这是我的代码示例

 #include "pch.h"
 #include <Windows.h>



 BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
 {


 switch (ul_reason_for_call)
 {
 case DLL_PROCESS_ATTACH:
 case DLL_THREAD_ATTACH:
 case DLL_THREAD_DETACH:
 case DLL_PROCESS_DETACH:
    break;
 }
 return TRUE;
}


 BOOL ConfigDSN(
  HWND     hwndParent,
  WORD     fRequest,
  LPCSTR   lpszDriver,
  LPCSTR   lpszAttributes) {
  MessageBox(NULL, L"TU", L"OVDJE", 0);
  return TRUE;
 }

 BOOL ConfigDriver(
  HWND    hwndParent,
  WORD    fRequest,
  LPCSTR  lpszDriver,
  LPCSTR  lpszArgs,
  LPSTR   lpszMsg,
  WORD    cbMsgMax,
  WORD* pcbMsgOut) {
  MessageBox(NULL, L"TU", L"OVDJE", 0);
  return TRUE;
 }

When I try to Add a new DSN none of the message box shows.当我尝试添加新的 DSN 时,没有消息框显示。 在此处输入图片说明

If I add Message box call inside a DLLMain function, then the message box is displayed.如果我在 DLLMain 函数中添加消息框调用,则会显示消息框。 I'm assuming I missing a fundamental c++ knowledge in building dlls.我假设我在构建 dll 时缺少基本的 C++ 知识。 Because I saw some .def files in resource folder inside postgres source code.因为我在 postgres 源代码中的资源文件夹中看到了一些 .def 文件。

My question is how I need to make this dll so I could create a DSN with my own driver ?我的问题是我需要如何制作这个 dll 以便我可以用我自己的驱动程序创建一个 DSN?

Since you are building C++ code, all function names will be mangled .由于您正在构建 C++ 代码,因此所有函数名称都将被破坏 The ODBC functionslity probably expects to use the un-mangled names. ODBC 功能可能希望使用未损坏的名称。

Use extern "C" to prevent name mangling:使用extern "C"来防止名称混淆:

extern "C" BOOL ConfigDSN(...) { ... }

extern "C" BOOL ConfigDriver(...) { ... }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM