|
In Continuation with WhiteSky,
better option will CStdioFile, which deal will Text based File
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
VinayCool wrote: ...but its not working
What is not working? Be specific.
VinayCool wrote: file.Open(str);
It is not necessary to call the Open() method. The constructor has already done this.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
try this;
char buff[] = "Test Data";
CStdioFile file("c:\\Test.txt", CFile::modeCreate | CFile::modeWrite);
file.WriteString( buff );
file.Close();
i think you forget to set file creation open flag.
|
|
|
|
|
Hi!
Please, can you give me a link to find out the way to define/declare a function in C++, export it as a 'standard' dll, and then use it in a basic program.
I need to do this only to understand the procedure,
so the function can be very very simple; something like this:
extern "C" int Foo(int param){<br />
return param+3;<br />
}
Cheers,
Russell
|
|
|
|
|
Lets see if this can help you
Just giving a try on this.
The module definition file lists the functions exported by a dynamic link library. All you have got to do is to list the names of the functions you are exporting to the EXPORTS section of the file
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I think that I'm near to the solution:
I'm trying to follow this example(http://www.it-lang-vb.net/Documentazione/Articoli/DllxVb.htm[^])(sorry but the comments are in italian lenguage), but I'm using VS.NET 2003 and this, probally, is creating compilers version problems.
Do you know if this code lines are not compatible with my version of VS?
Cheers,
Russell
|
|
|
|
|
|
Hello. I'm currently working on a program which uses DHTML for user interface, and some elements of the interface need to be called on network events (so without the user clicking on anything). All samples on CodeProject use user clicks, and actually the other method fails! Let me explain.
I've actually created a new project to show the problem. You'll find it on http://temp.alishomepage.com/.RMI/JavaScript.zip. That project has been created to show the JavaScript call problem with the CHtmlView class: failure in the execScript method when called from a thread.
The project has been generated by Visual C++ 6 as a standard MFC project with CHtmlView as the view class. All changes in files are marked with the comment "JavaScript problem sample", and involve the JavaScriptView.h and .cpp files.
In JavaScriptView.h, there's an override of the OnDocumentComplete method.
In JavaScriptView.cpp, we add the two header files (atlbase.h and mshtml.h) as well as the the following function (headers are needed by the function):
<br />
DWORD WINAPI CallJScriptLater( LPVOID lpParam )<br />
{<br />
CComQIPtr<IHTMLDocument2> pHtmlDoc( ((CJavaScriptView*) lpParam)->GetHtmlDocument() );<br />
<br />
CComPtr<IHTMLWindow2> pWnd;<br />
pHtmlDoc->get_parentWindow( &pWnd );<br />
<br />
CComBSTR bstrMember(CString("alert('boo')"));<br />
<br />
CComBSTR vtlanguage(CString("javascript"));<br />
VARIANT vresult;<br />
<br />
pWnd->execScript(bstrMember,vtlanguage,&vresult);<br />
<br />
return 0;<br />
}<br />
And the added function is called on document complete:
<br />
void CJavaScriptView::OnDocumentComplete( LPCTSTR lpzsURL )<br />
{<br />
CHtmlView::OnDocumentComplete( lpzsURL );<br />
<br />
#if 1<br />
CallJScriptLater( this );<br />
#else<br />
CreateThread( NULL, 0, CallJScriptLater, this, 0, NULL);<br />
#endif<br />
<br />
}<br />
Finally, OnInitialUpdate has been changed:
<br />
void CJavaScriptView::OnInitialUpdate()<br />
{<br />
CHtmlView::OnInitialUpdate();<br />
<br />
Navigate2(_T("about:blank"),NULL,NULL);<br />
}<br />
As a result, the program:
- On initializatio complete, loads about:blank
- When loading complete, calls executes the JavaScript: alert('boo')
That call may be in two ways:
- Directly (if the OnDocumentComplete has #if 1)
- Via a thread (if the OnDocumentComplete has #if 0)
PROBLEM: The direct call (JavaScript_directCall.exe) succeeds whereas the thread call (JavaScript_threadCall.exe) fails.
If anyone has a solution please let me know.
Thank you
S. Ali Tokmen
http://ali.tokmen.com
|
|
|
|
|
Now that's really odd...
Have you tried creating the thread with AfxBeginThread?
I'm asking because Microsoft claims the other methods aren't MFC-safe.
|
|
|
|
|
Hello, HAND
Thank you for your reply. Using AfxBeginThread instead of the CreateThread function doesn't unfortunately solve the problem... If you want to see the exact project, please look at http://temp.alishomepage.com/.RMI/JavaScript.zip
I think the issue is due to the fact that the one of those objects there (CHtmlView, presumably) is created in mono-thread mode and does not accept script calls from other threads. Even worse, if the host has Internet Explorer 5 installed (default Windows 2000 SP4 configuration) the script call makes the program crash! See http://support.microsoft.com/kb/318426
I'm starting to have a solution idea, thought: creating the entire HTML output using the IHtmlDocument2::write method and then calling JavaScript from there. It seems to work, but has a majot disadvantage: every JavaScript call adds at least one line to the source code!
Another idea would be JavaScript to "ping" the C++ at regular intervals and C++ to catch that and respond using a JavaScript call.
Thank you for your reply.
S. Ali Tokmen
http://ali.tokmen.com
|
|
|
|
|
Hello, everyone
First of all, I would like to thank everyone who has helped identifying the cause of this issue and, of course, proposed ideas of solution.
The problem seems to be that the scripting object of the IHtmlDocument interface (in its current -Windows XP SP2- implementation) has some protection against access to its inner elements from external threads. As a result, calls from other threads to function that get the content of an HTML document or call scripts on it is prohibited.
There's a solution, thought: create a class which would try to call a script using standard methods and on failure queue the request. That class should of course also have a method to execute all queued calls (you can use CList for that queue).
Then, you have to find a method to get in the same thread as the CHtmlDocument interface... Which is not that hard: first, put the setInterval("window.navigate('refreshjs:')",1000) line in your HTML document as a JavaScript. This will, every second, try to navigate to refreshjs:
Second, you have to modify the OnBeforeNavigate method of CHtmlView to make it call the queue execution method if a navigation to refreshjs: is requested (note that you can also stop navigation at that point -refreshjs: is not a valid protocol anyway!)
Using this method, JavaScript calls that fail will be re-executed at most one second later... And shall now not fail, except if you've really called a function that doesn't exist!
S. Ali Tokmen
http://ali.tokmen.com
|
|
|
|
|
Hi,
I am using CSocket class to transfer a file.
I am creating 2 socket at server side that are listening, one is doing normal communication with client to send and recevie normal information , 2nd on is used when file is transfer, so there will be no intruption when file and normal information is transfered,
Is it a better approach to have 2 sockets as i have in my application?
Regards.
|
|
|
|
|
zahid_ash wrote: one is doing normal communication with client to send and recevie normal information , 2nd on is used when file is transfer
What you meant by Normal communication and File Transfer? in both case you are send/rcving data?
Loka Samastha Sukhino Bhavanthu..!!!
( May all beings be happy and free )
|
|
|
|
|
|
|
Hi Noname,
this will help u
http://www.codeproject.com/cpp/data_conversions.asp
Regards,
Vinay Charan.
|
|
|
|
|
CString::GetBuffer(...);
CString csStr = _T( "Somestring" );
LPCTSTR szBuff = (LPCTSTR)csStr;
LPTSTR szBuff1 = csStr.GetBuffer();
LPTSTR and LPCTSTR are WCHAR* and CONST WCHAR* type respectively.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
wchar_t *pwsz1=NULL;
CString str;
str="Hi";
pwsz1=str.AllocSysString();
-------------------------------------
WCHAR pwsz[1024];
CString Test2="Hi";
MultiByteToWideChar( CP_ACP,0,Test2,-1,pwsz,sizeof( pwsz));
------------------------------------
WCHAR* pwsz2;
CString Test3="Hi";
pwsz2=new (WCHAR);
MultiByteToWideChar( CP_ACP, 0, Test3,-1, pwsz2, sizeof( pwsz2 ) );
whitesky
|
|
|
|
|
NoName II wrote: how to convert CString to const WCHAR *
mbstowcs
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
SupportCRY- Child Relief and You
|
|
|
|
|
Hi, there,
I would like to realize a function that can create a folder called "data" in a directory if it doesn't exist. Here is my code:
CString strPath ="D:\\temp";
SetCurrentDirectory(strPath);
CFileFind ff;
BOOL btmp1 = ff.FindFile("data");
if(btmp1)
{
BOOL btmp2 = ff.FindNextFile();
if(!ff.IsDirectory())
{ //*************************//
if(!CreateDirectory(LPCTSTR(strPath+"\\data"), NULL))
{
ff.Close();
return FALSE;
}
}
}
else
{
if(!CreateDirectory(LPCTSTR(strPath+"\\data"), NULL))
{
ff.Close();
return FALSE;
}
}
ff.Close();
return TRUE;
Then I noticed a strange thing. If there is a file in "D:\\temp" named data, the CreateDirectory function after //***// part always fails. Please note that the existing data is a file without extension, not a folder. So I added a line to the //***// part:
CFile::Rename(strPath+"\\data", strPath+"\\data.bak");
then the CreateDirectory function can succeed and the folder data is created. Sadly, I won't be able to change the file data.bak to data anymore because there is a folder with the same name.
How could this happen? Or is it because I missed anything ? Your help will be greatly appreciated.
David
|
|
|
|
|
David L.S. wrote: I would like to realize a function that can create a folder called "data" in a directory if it doesn't exist. Here is my code:
Instead of CFIleFind for Checking existence of Folder or File, why not you use Direct api PathFileExists()
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
SupportCRY- Child Relief and You
|
|
|
|
|
So what are you expecting CreateDirectory() to do when a file named c:\temp\data already exists?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hi,
Thanks for your answers. I now know the reason I couldn't do that. Thanks anyway.
David
-- modified at 22:04 Friday 26th May, 2006
|
|
|
|
|
I've developed a single document application and I use Dialog bars.
I've derived a class from CDialogBar in order to map OnCtlColor and
I use that class as base class.
Then I've derived a class (from my base class)for any dialog bar and
I use its instances in CMainFrame instead of default CDialogBar instance
created by Visual Studio.
I've written a specific class for any dialog bar in order to manage
its events in that class instead of in CMainFrame class.
(Otherwise, having many dialog bars CMainframe class becomes a very
big and complex class).
My problem is the following:
Visual Studio allows me to create methods for any event of my dialog
bar in the specific class but at runtime that methods are never called.
It seems that there is no real association between UI controls and methods
written in my class (and added with class wizard).
All works if I copy that methods and the related MESSAGE_MAP code
in CMainframe class.
Why my classes doesn't catch dialog bars event while CMainframe do it ??
Thanks a lot.
|
|
|
|
|
Visual Studio 7.0 I presume? It's full of such bugs and once in a while I think of rolling back to my favorite 6.0.
|
|
|
|