|
Steps
- Analyze matlab code to understand it. This might involve researching matlab provided methods.
- Learn C
- Use the above to write C code.
Researching existing C libraries might also be helpful.
|
|
|
|
|
Best answer really... I have yet to see a "code converter" that did a good job without generating cluttered, hard to read code (that can run slow compared to if you have just done the conversion manually).
|
|
|
|
|
Quote: how to call a function inside another function in file like utility.c
|
|
|
|
|
That question is impossible to answer. Please give some proper detailed context about your problem. Calling a function is just the same wherever you call it from.
|
|
|
|
|
utility.c file consist of following function:
function list_file_directory()
{
}
function wavread()
{
// reading the .wav file;
}
function noise
{
//here i want to call the both above function and perform futher calculation //is it possible?
}
main.c
{
call function 1
{display}
call function 2
{
display
}
}
|
|
|
|
|
maibam debina wrote: i want to call the both above function and perform futher calculation //is it possible? Of course it is; just call them. What is your problem with this?
|
|
|
|
|
It can not be understood. Could you tell more detail?
|
|
|
|
|
In C, you cannot define a function inside another function. All functions must stand on their own.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Quote: error: invalid operands to binary / (have ‘float’ and ‘int *’)
how to solve this error?
|
|
|
|
|
You can't divide by a pointer. You can divide by what it points to, but you cant divide the pointer itself.
Take a look at the following. Basically, you need to dereference the pointer, as I've done in #3.
#include <cstdio>
int main()
{
int numerator = 10;
float denominator = 2.7;
float result = numerator / denominator;
printf("%d / %f = %f\n", numerator, denominator, result);
int *ptrToNumerator;
ptrToNumerator = &numerator;
result = ptrToNumerator / denominator;
printf("%f\n", result);
result = *ptrToNumerator / denominator;
printf("%f\n", result);
return 0;
}
|
|
|
|
|
<blockquote class="quote"><div class="op">Quote:</div>
for(i=0;i<*SizeOfData;i++)
{
datasample[i]=square(samplesValue1[i]);
squaring1=(datasample[i]*datasample[i]);
sum +=squaring1;
}
summation_input=(float)sum/ *SizeOfData;
printf("\n%f",summation_input);
fclose(fp);</blockquote>
wen i change summation_input=(float)sum/SizeOfData;
to summation_input=(float)sum/ *SizeOfData some unknown error is generating given below
Quote: dithermain.c text+0x430): undefined reference to `square'
collect2: ld returned 1 exit status
|
|
|
|
|
That error is telling you that the linker can't find the function body for your function square .
If it's in another c/cpp file, you have to compile and link it too.
Otherwise, you can just place the square function in the same c/cpp file, but make sure it appears before it's first used. (otherwise you'll get a compiler error that says the symbol is unrecognized)
|
|
|
|
|
in function after writing return();
is it possible to continue process will it be effective ?
|
|
|
|
|
maibam debina wrote: in function after writing return();
is it possible to continue process... Not in that same function.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I have 2 dlls where one is run time loaded (Run.dll) and calls the other(other.dll)
Also the application calls the other.dll as well.
Now the other.dll has a static variable in it that is only used in itself i.e internally to the dll which gets changed by one of it's functions.
At the start of the program I call a this function in the other.dll to set the variable but later on when I run time load the run.dll which calls the function in the other.dll the variable is not set.
I thought the any variables in the other.dll which is statically linked to the app and to the run.dll will only have one instance of itself in memory especially regarding the variables?
How can I solve it to ensure that the variable in other.dll is the same across the process?
I forget to mention that I'm using the windows api etc.
|
|
|
|
|
It's difficult to visualise the actual sequence of events here, but it may be that on the second call into this dll it is getting reloaded somehow. Either that or there is another bug somewhere.
|
|
|
|
|
You wont be able to access anything in other.dll declared in such a way from Run.dll because they will have different instance handles. The only thing preventing a big crash in try to do so will be MFC's safe pointers because it is an access violation to allow it.
There are two ways around the problem provide a function that returns the status on a standard DLL interface function something like
int OtherDLLStatus (void) {
return (OtherDLLStaticVar);
};
Then publish it on the DLL interface and get the static variable status via that call. I think that is probably all you need.
However Option 2 is use shared memory mapping
http://msdn.microsoft.com/en-us/library/ms810613.aspx[^]
In vino veritas
|
|
|
|
|
Hi,
I am trying to call a MFC dialog based regular dll from other application. The dll function "BOOL CApplicationApp::InitInstance()" does not call to any dialog. I want to trigger UI on the click on button so i created a exported function which call first dilaog of application. But when I create a object of class it does load resource I think so crashed.
Suggest me how to do?
|
|
|
|
|
You could step into the exported function using a debugger to find what is going on.
MFC DLLs require the first line of a function to be - AFX_MANAGE_STATE(AfxGetStaticModuleState());
If you haven't done that, you could try by putting that as the first line of the exported function.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
The short answer is between very difficult and you can't do this because not all of MFC is thread safe.
There are specific parts of MFC designed for threading general background
http://msdn.microsoft.com/en-us/library/975t8ks0%28v=vs.90%29.aspx[^]
The tips page will give you the specific problem
http://msdn.microsoft.com/en-us/library/h14y172e%28v=vs.90%29.aspx#_core_accessing_mfc_objects_from_non_2d_mfc_threads[^]
QUOTE:
If you have a multithreaded application that creates a thread in a way other than using a CWinThread object, you cannot access other MFC objects from that thread. In other words, if you want to access any MFC object from a secondary thread, you must create that thread with one of the methods described in Multithreading: Creating User-Interface Threads or Multithreading: Creating Worker Threads. These methods are the only ones that allow the class library to initialize the internal variables necessary to handle multithreaded applications.
In vino veritas
|
|
|
|
|
Hi i am doing a program with a clistctrl with custom draw and i have custom highlight color bar.
Now my problem is when i am with mouse on CListCtrl the bar is color i wish, when i leave to go on other control
i don't know how change the color in gray of the highlight bar, i post the code for you:
void CPubFoldersView::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pCD = (NMLVCUSTOMDRAW*)pNMHDR;
int nRow = pCD->nmcd.dwItemSpec;
CListCtrl& m_MainTable = GetListCtrl();
CString szInEvidence;
pCD->nmcd.uItemState = CDIS_DEFAULT;
if (VirtualRowArray.GetCount())
szInEvidence=VirtualRowArray[nRow].Field[4];
switch(pCD->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
{
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)==LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(167,205,240);
*pResult = CDRF_NEWFONT;
}
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)!=LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(197, 206, 216);
*pResult = CDRF_NEWFONT;
}
}
break;
default:
*pResult = CDRF_DODEFAULT;
}
}
|
|
|
|
|
Perhaps I misunderstand your problem, but it sounds like all you are missing is to check if the list control itself has focus. If it does, you set the color as you are doing now, otherwise you set the gray color.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
No i need to draw gray when i leave the row selected but i click on another control.
|
|
|
|
|
Right. In that case the other control has the focus, not the list control. Note, that this is different than a row within the list control having the focus state.
Your code for that could look something like this (I did not try to compile it so there might be errors):
case CDDS_ITEMPREPAINT|CDDS_SUBITEM:
{
if (::GetFocus() != m_MainTable.m_hWnd)
{
pCD->clrTextBk = RGB(192, 192, 192); *pResult = CDRF_NEWFONT;
}
else
{
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)==LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(167,205,240); *pResult = CDRF_NEWFONT;
}
if (m_MainTable.GetItemState(nRow, LVIS_SELECTED)==LVIS_SELECTED && m_MainTable.GetItemState(nRow, LVIS_FOCUSED)!=LVIS_FOCUSED)
{
pCD->clrTextBk = RGB(197, 206, 216); *pResult = CDRF_NEWFONT;
}
}
break;
}
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
You are a MASTER!!!! you solved me the problem THANKS THANKS!!!!
|
|
|
|