Pass DWORD pointer by using 'calllib' to c function

16 ビュー (過去 30 日間)
pavel
pavel 2015 年 3 月 9 日
コメント済み: Philip Borghesani 2015 年 3 月 11 日
hi,
I'm trying to pass values by using 'calllib' to c function.
The input of the function is a dword pointer,how can i create dword pointer?
p.s I can't change the dll, the code must be on the matlab side.
c:
Counter(DWORD* Packets)
matlab:
my_pointer= libpointer('______'); % here is the question
calllib('c_dll','Counter',my_pointer)
TNX

採用された回答

Philip Borghesani
Philip Borghesani 2015 年 3 月 9 日
A DWORD is a uint32 in matlab but no libpointer or conversion should be necceary.
You did not give enough information to formulate a full answer but here are some suggestions. A pointer object should not be needed to call this function.
If the function has a return value try:
[retval, newcounterval]=calllib('c_dll','Counter',0) % or whatever value counter wants as input
If you feel you need a pointer then use:
my_pointer=libpointer('uint32Ptr',0)
retval=calllib('c_dll','Counter',my_pointer)
newcountervalue=my_pointer.value
If you are getting error messages then please let us know what is happening. Frequently use of DWORD by a library requires adding windows.h to the included header or making a new header.
  2 件のコメント
pavel
pavel 2015 年 3 月 11 日
Hi, First of all thanks for the quick response. I can't use the first option, because the c function changes the pointer's value and only returns 'pass' or 'fail' status. The second option worked great. thank you very mutch.
Philip Borghesani
Philip Borghesani 2015 年 3 月 11 日
The first syntax should still work. the pass fail status will be in retval and the modified counter value will be in newcounterval. If the function continuously modifies the counter after the call then the second syntax is required and the situation is dangerous because the process MUST be stopped before the pointer variable goes out of scope.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C from MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by