|
Glad to be of help..
John
|
|
|
|
|
i am using a visual studio add in.
in one of the methods i am using
CWinApp* pApp = AfxGetApp();
i need to get a pointer the visual studio app, not the add in app,
in both cases, even if i use or don't use AFX_MANAGE_STATE(AfxGetStaticModuleState()); i get a pointer to the add in app
and not the pointer to the visual studio (exe)
how can i retrieve the pointer to the visual studio exe???
thanks
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Can you give me an information about how to use af_irda.h in C++ ?
I think that I could access my cell phone via Irda connected to my PC using af_irda.h. Isn't it correct ?
I've downloaded some examples and articles, but they are for Windows.CE not Windows XP. Can you give me a sample code to do that ?
I've tried to include af_irda.h but there were few errors when I run the application. Can I use af_irda.h in Visual C++ 6.0 ?
Or there any other way to access my cell phone in simple and direct way ?
Thanks a lot.
|
|
|
|
|
Communication between the phone and the PC can be established in the following ways:
1.RS232 serial port
2.IrDA
3.Bluetooth
Whether you believe or not all three ways work the same way, namely by sending so called AT commands to the phone and receiving an answer.
I would recommend you to look up Device I/O in the PlatformSDK, especially functions like ReadFile and CreateFile,WriteFile, and ReadFile (yes, they are called file!).
they will tell you have to communicate over the serial port.
You can use the same functions for communicating over IrDa and Bluetooth, because both implement an RS232 serial interface. From the point of view of your code, the only difference is that you use the device's name when opening them with CreateFile (e.g. IRDAx or BTHx instead of COMx).
Peter Molnar
|
|
|
|
|
Hi Peter, I'm a begginer in this, i know that this section is For C++ only, but I have the same problem to comunicate to my cell phone, and I'm very confused now.
I have already try CreateFile,ReadFile,and WriteFile Function as you tell us on this message board.
I try those using Visual Basic by declaring CreateFile Function with kernel32.dll as the library.
the problem is there is no file created when the programm's running, even on my drive C:\.
this is my code.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
CF=CreteFile("C:\tester.txt",GENERIC_WRITE, _
FILE_SHARE_READ,0,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,0)
if CF<>-1 then
'write file function
else
msgbox "Error Message"
end if
CloseHandle(CF)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I have try to change the first parameter with "\\.\c:\tester.txt" or "\\.\irda1\tester.txt" but the result is same, there's nothing happen.
I hope you can give me a sugestion or maybe you can tell me where i can find the example programm in VB or VB.NET
Thank you Very Much!!! and im sory, my english is not very good;P
|
|
|
|
|
hi peter, i have try again and it works,the programm can
detect my irda device on com3. but when i start to send the
AT Command to the phone by using WriteFile function,
there's no reaction.
and then i want to translate the working code into VB.net,
but the result will not correctly why???
can you help me????please
|
|
|
|
|
Hi Ivan,
sorry for not answering for a long time but I was away from my desk.
As for porting C++ code to VB.NET, I am not familiar it but I definetaly know -just as you write- that it is possible to call Win32 API functions from VB.NET code.
Comments on your code:
1.The first param of CreateFile is a string like "COM1" or any other string describing the communication device's name. Inspite of the function name NO file is actually created. Use GENERIC_READ | GENERIC_WRITE access flags.
2.CreateFile returns a handle which identifies the opened communication port. Using this handle you can call WriteFile to send AT commands to the device and later on ReadFile to check for response.
3.In order to not block your channel forever, and receive your info you should poll the port for answer (of course only after you have successfully sent to it an AT command) in a loop with ReadFile for a pre-defined, device specific period of time. You should collect the returned info in a buffer.
4.A successfully opened device that you communicate with ALWAYS returns a response regardless of whether the given AT command is understood by the device or not.
Possible responses are "\r\nERROR\r\n" if the AT command is not known to the device, or "\r\nSOME INFORMATION\r\n\r\nOK\r\n" if the sent AT command is supported, where \r\n is 0x0d and 0x0a.
Peter Molnar
|
|
|
|
|
hi peter, finally i've made it with visual c++ 6.0
but, this is will only success if i use windows XP as the operating system,
and failed when i try those in win2000pro or win 2000 server.
maybe i should told you that my irda device can only be attached to the usb, not to the serial port. so i can't use my code to send or recieve any information.
and maybe you can told me for the suitable path that i can use for accesing this usb irda device, instead of com3 that will only automatically show up (added to the com port list) when i beam my cellphone's irda in windows XP OS not to win 2000.
i have try what you told to write IRDAx as the path but this's failed
please help me
thank's very much!
note:
i also email you this post.;)
|
|
|
|
|
HI,
IrDA really implements a VIRTUAL serial port by means of its device driver, and it is also the device driver which is responsible for the device to be recognized by the OS, and XP has definitely more built-in drivers than previous OSs. Virtual means that an IrDA device can really be manipulated like a real COM port although it is not.
Since I dont have any real experience specifically with IrDA I suggest you to consult the device manufacturer's documentation.
Peter Molnar
|
|
|
|
|
Hi,
I have the following scenario:
class CFoo
{
public:
int Foo();
static CFoo * CreateFoo() { return new CFoo; }
};
void * GetNewFooHandle() { return (void *) CFoo::CreateFoo(); }
int FooFoo(void * fooHandle) { return ((CFoo *)fooHandle)->Foo(); }
I don't it done with the declarations (I played around with __cdecl / extern "C" etc.)
Any pointers? (Or a sample would be nice)
Flirt harder, I'm a coder.
mlog || Agile Programming | doxygen
|
|
|
|
|
what kinda of error are you getting.
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
Sorry for the late reply - I got it working.
Error was function not found at linkage.
Found out that in a .cpp file, you can call CPP stuff even in an funciton that is declared extern "C"
So things look like this:
#ifdef __cplusplus
class CFoo { ... };
#endif
#ifdef __cplusplus
extern "C" {
#endif
void * FooCreate();
int FoFoo(void *);
#ifdef __cplusplus
}
#endif
CFoo * CFoo::CreateInstance() { ... };
int CFoo::Foo() { ... }
extern "C" void * FooCreate() { return (void *) CFoo::CreateInstance(); }
extern "C" int FooFoo(void * f) { return ((CFoo *)f)->Foo(); }
Cool!
I'm not sure if this is a VC6 only thing - but that shouldn't hurt me much
Flirt harder, I'm a coder.
mlog || Agile Programming | doxygen
|
|
|
|
|
Does C has classes?
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
No, so this will not compile. You have to put the code of the function that uses the class inside the .cpp file.
John
|
|
|
|
|
declaring extern C or not will only tells the compiler how to mangle the function the c++ way or the c way... nothing changes in its functionality.(yeah linking should be carefully done)
My God is more powerfull Than Your God. (the line that divides the world)
|
|
|
|
|
This will help you in accessing the static member function of C++ in C.
//Test1.cpp
#include <iostream.h>
typedef int (* pFunc) (int,int);
class D {
public :
static int Calculate(int iNum1,int iNum2);
};`
extern "C" {
int D::Calculate(int iNum1, int iNum2) { return iNum1 + iNum2; }
pFunc p = D::Calculate;
}
// Test.c
#include <stdio.h>
typedef int (* pFunc) (int,int);
extern pFunc p;
int main() {
int iResult = (*p)(10,20);
printf("Value is %d",iResult);
return 0;
}
Hope this will help you!
Regards
Dinesh
|
|
|
|
|
How to read and edit the id3 tag for a wma file?
There are functions in the windows media SDK to do it but this involves linking in to a pretty big library for what is a simple operation.
Does anyone know how to do this simply?
|
|
|
|
|
Hi Everybody,
Whenever i create an object of Derived CFrameWnd class, it doesn't have any view attached to it. Can I associate a CHtmlView class with Derived CFrameWnd class by calling SetActiveView ?
Is there any other way to attach the CHtmlView with the Derived CFrameWnd class, so that i should be able to display the dynamically prepared HTML in that Derived CFrameWnd object.
Regards
Dinesh
|
|
|
|
|
i've created a visual studio add in using the wizard.
i copied a method from other project (that i found here in code project) that retrieves the *.dsw file path.
here is the code:
CString CCommands::GetWorkspacePath()
{
CWinApp* pApp = AfxGetApp();
CString szWorkspace;
POSITION posdt = pApp->GetFirstDocTemplatePosition();
while (NULL != posdt)
{
CDocTemplate* pdt = pApp->GetNextDocTemplate(posdt);
if (0 == strcmp("CProjectWorkspaceDocTemplate",
pdt->GetRuntimeClass()->m_lpszClassName))
{
POSITION posdoc = pdt->GetFirstDocPosition();
if (NULL == posdoc)
break;
CDocument* pdoc = pdt->GetNextDoc(posdoc);
if (NULL == pdoc)
break;
szWorkspace = pdoc->GetPathName();
if (0 == szWorkspace.GetLength())
break;
}
}
return szWorkspace;
}
problem is that this line :
POSITION posdt = pApp->GetFirstDocTemplatePosition();
returns NULL for the postd. when i try this code in the other project it works ok
please, i already post this question before, and didn't get any reply
can any1 help me?
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
you are getting Null value returned by
pApp->GetFirstDocTemplatePosition()
bcoz you are using the base class pointer, and the base class pointer in not aware your projects Doc Template positions. If you type cast it into your project's application class, it won't return null value;
CWinApp* pApp = AfxGetApp();
CString szWorkspace;
((MyPrjApp*)pApp)->GetFirstDocTemplatePosition();
never say die
|
|
|
|
|
thanks for the response, that didn't work!
here is what i wrote and i got still a null:
CWinApp* pApp = AfxGetApp();
CString szWorkspace;
POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition();
i even try the extern thing:
extern CBackITUp_AddinApp theApp;
.
.
POSITION posdt = theApp.GetFirstDocTemplatePosition();
that didn't work as well!!!
please please i need help
(try to create a new visual studio add in project in VC6, then try the lines above, you will get the same result.....i am doing something wrong, but i can't figure out what is wrong....
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
CWinApp* pApp = AfxGetApp();CString szWorkspace;//POSITION posdt = pApp->GetFirstDocTemplatePosition();POSITION posdt = ((CBackITUp_AddinApp*)pApp)->GetFirstDocTemplatePosition();
this code runs well when i executed it in newly created project. i executed this code in CMainFrame class message handler function.
i suggest you to try this code in CMainFrame Class for testing purpose only
the problem could be in base class of CCommons class, you haven't mentioned anything about its base class.
never say die
|
|
|
|
|
thanks for reply.
As I mentioned before, I am using a visual studio add in project the objects:
1. CBackITUp_AddinApp - the application
2. CCommands - the commands object
3. CDSAddIn - the developer studio add in object
4. ICommands - the commands interface
as you can see i am not using CMainFrame.....
I think I know what my problem is. the method GetFirstDocTemplatePosition will work only on the dev studio exe (the application which runs the add in) and not on the add in itself....
therefor when i am using
CWinApp* pApp = AfxGetApp()
I am getting a pointer to the add in (dll) main application object and not the exe main application object.....
now can you help?
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
according to me, you can solve the problem by creating a DLL project which has a fuction MyFunc() returning application object's address. Include this Dll in your addin and call MyFunc().
never say die
|
|
|
|
|
Hi,
I am not sure i follow, can you show me code on how to do that?
thanks
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|