JAVA调用VC++的DLL。这是JAVA代码
public class JavaCall {
static {
System.loadLibrary("changebk");
}
   
public native static void changeecl(String s); public static void main(String[] args) {
JavaCall jc = new JavaCall();
 String strDesktop="E:\\coco.gif";
jc.changeecl(strDesktop);
System.out.println("调用结束");
}
}这是VC++代码。他的作用是设置桌面背景为e:\\ibmee.gif
NIEXPORT void JNICALL Java_JavaCall_changeecl (JNIEnv *env, jclass cls,jstring str)
{
IActiveDesktop   *pAD;     
COMPONENT   comp; 
CoInitialize(NULL);
CoCreateInstance(  CLSID_ActiveDesktop,   NULL,   CLSCTX_INPROC_SERVER,     
IID_IActiveDesktop,   (void**)&pAD   );   
pAD->SetWallpaper(L"e:\\ibmee.gif",0);   
pAD->ApplyChanges(AD_APPLY_ALL);   
pAD->Release(); 
CoUninitialize();

现在我想根据JAVA传过来的String 类型的参数strDesktop来灵活设置桌面,而不是在VC++中象  pAD->SetWallpaper(L"e:\\ibmee.gif",0);   这样写死。应该怎么修改???

解决方案 »

  1.   

    没有做过不过用String得到char数组或者byte数组,由vc来使用应该可以吧
      

  2.   

    pAD->SetWallpaper(env->GetStringUTFChars(str, false), 0);
      

  3.   

    楼上的VC编译时报
    --------------------Configuration: changebk - Win32 Debug--------------------
    Compiling...
    changebk.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\changebk\changebk.cpp(23) : error C2664: 'SetWallpaper' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    执行 cl.exe 时出错.
      

  4.   

    pAD->SetWallpaper((unsigned short *)env->GetStringUTFChars(str, false), 0);
      

  5.   

    自己看看吧,会有点帮助的
    http://www.blogjava.net/sunking/archive/2006/04/03/38981.aspx