利用rundll32.exe來運行自訂的dll匯出函數

來源:互聯網
上載者:User

因為安裝指令碼中需要調用到我們的一個dll中的匯出函數,於是有了下文。
重要參考:INFO:Windows Rundll 和 Rundll32 介面
http://support.microsoft.com/kb/164787

剛開始不知道原來rundll對調用的匯出函數的原型進行了限制,導致
"嘗試運行 XXX 時發生意外"
在dll中assert出來,並attatch到rundll32進程,發現參數不對,完全不是我想的那樣,於是上網搜尋,還好找到了msdn上的這篇文章,哈哈哈

32 位 DLL:

  void CALLBACK
  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
    

知道問題,解決起來就方便多了,代碼:

void CALLBACK RundllFuncExample(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow){ USES_CONVERSION; if (lpszCmdLine) {  int nArgs = 0;  // 這裡用了shell api +_+ 關於這個函數請查看MSDN  LPWSTR* szArglist = ::CommandLineToArgvW(A2W(lpszCmdLine), &nArgs);  if (NULL != szArglist   && nArgs == REGAPP_ARG_NUM )  {   // 調用真正的dll函數  } }}

調用例子:

RUNDLL32.EXE "example.dll",RundllFuncExample arg1 arg2 arg 3 arg 4 arg 5

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.