该DLL是VB生成的,没有lib,没有def,只有一个dll
在VB中调用方法如下:Dim obj as Object
Dim strRet as string '返回的Xml数据Set Obj=CreateObject( TestDLL.TestDistribute)
Str=obj.Process("something as string") 在VS.NET中查看该DLL,得知该DLL中有一个类叫“TestDistribute”,该类有一个方法叫
Process(String strXML),查MSDN中有C#调用的方法:#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
namespace SysWin32
{
[DllImport("user32.dll", EntryPoint = "MessageBox", CharSet = Unicode)]
int MessageBox(void* hWnd, wchar_t* lpText, wchar_t* lpCaption,
unsigned int uType);
}
int main( )
{
SysWin32::MessageBox( 0, L"Hello world!", L"Greetings", 0 );
}如何在VC++中写一个DLL封装对TestDLL 中的TestDistribute.Process方法?
我的错误代码如下:其实我需要在java中调用 TestDLL JNIEXPORT jstring JNICALL Java_Java_Process
(JNIEnv *, jclass, jstring jstrXML){ HINSTANCE hdll = LoadLibrary("TestDLL");
if (hdll == NULL)
{
printf("DLL Can't find!!!!");
return NULL;
}
QueryInterface(
DoProcess doPrc=(DoProcess)GetProcAddress( hdll,"Process");//??(hdll, "TestDistribute.Process")??
if (doPrc==NULL)
{
printf("Function Can't find!!!!");
return NULL;
}
return doPrc( jstrXML ); iDistribute iU8Class;
return iU8Class.Process(jstrXML);
*/
}
久思不得其解……苦闷ing,另外 jstring 在VC++中用什么和 java 与 VB 的string 对应起来??
在VB中调用方法如下:Dim obj as Object
Dim strRet as string '返回的Xml数据Set Obj=CreateObject( TestDLL.TestDistribute)
Str=obj.Process("something as string") 在VS.NET中查看该DLL,得知该DLL中有一个类叫“TestDistribute”,该类有一个方法叫
Process(String strXML),查MSDN中有C#调用的方法:#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
namespace SysWin32
{
[DllImport("user32.dll", EntryPoint = "MessageBox", CharSet = Unicode)]
int MessageBox(void* hWnd, wchar_t* lpText, wchar_t* lpCaption,
unsigned int uType);
}
int main( )
{
SysWin32::MessageBox( 0, L"Hello world!", L"Greetings", 0 );
}如何在VC++中写一个DLL封装对TestDLL 中的TestDistribute.Process方法?
我的错误代码如下:其实我需要在java中调用 TestDLL JNIEXPORT jstring JNICALL Java_Java_Process
(JNIEnv *, jclass, jstring jstrXML){ HINSTANCE hdll = LoadLibrary("TestDLL");
if (hdll == NULL)
{
printf("DLL Can't find!!!!");
return NULL;
}
QueryInterface(
DoProcess doPrc=(DoProcess)GetProcAddress( hdll,"Process");//??(hdll, "TestDistribute.Process")??
if (doPrc==NULL)
{
printf("Function Can't find!!!!");
return NULL;
}
return doPrc( jstrXML ); iDistribute iU8Class;
return iU8Class.Process(jstrXML);
*/
}
久思不得其解……苦闷ing,另外 jstring 在VC++中用什么和 java 与 VB 的string 对应起来??
在 VC 中的创建方法与 VB 相同,需要自己手动写一个 .h 文件或 .idl 文件生成类型库
之后导入类型库,使用 CoCreateInstance 创建对象
VC 中对应的 string 的使用 WCHAR
VB中这样初始化:Set Obj=CreateObject( TestDLL.TestDistribute)
VC中不能照搬呢,下面的代码是取不到方法句柄的:
DoProcess doPrc=(DoProcess)GetProcAddress(hdll, "TestDistribute.Process")
我奇怪DLL的命名空间和DLL中的类是什么关系……
VB 中 CreateObject 可以创建一个 short name 指定的 COM 对象,而 VC 中则要显示指定该 short name 的名称,这与 TestDistribute 的具体实现有关,VC 中是通过调用 CoCreateInstance 来创建的
你可以先把你的 DLL 发给我看一看: [email protected]