|
Basically, you want to break the rules of C++ and then complain about having to use an explicit cast to inform the compiler you really do want to break the rules and you don't care about the consequences. Why are you so resistive to the casts? And if this is a production environment, you need to inform future maintainers that you at least thought about the consequences of breaking the rules.
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
Does anyone know if it's possible to print graphics using Direct2D together with a printer-based HDC (i.e. CPrintInfo, DoPreparePrinting(), etc)?
Using the ID2D1DCRenderTarget interface and the BindDC method works just fine when drawing to a screen-based DC (or to a bitmap, which is blitted to screen later), but when the DC represents a printer the BindDC method returns E_INVALIDARG.
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_HARDWARE,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE),
0,
0,
D2D1_RENDER_TARGET_USAGE_NONE,
D2D1_FEATURE_LEVEL_DEFAULT);
ID2D1DCRenderTargetPtr pRT;
Globals::g_D2DFactory->CreateDCRenderTarget(&props, &pRT);
int sizeX=pDC->GetDeviceCaps(HORZSIZE);
int sizeY=pDC->GetDeviceCaps(VERTSIZE);
CRect rect(0, 0, sizeX, sizeY);
hr = pRT->BindDC(pDC->m_hDC, rect);
if (FAILED(hr))
{
const char* szErr = DXGetErrorStringA(hr);
const char* szDesc = DXGetErrorDescriptionA(hr);
ATLTRACE("BindDC: %s - %s\n", szErr, szDesc);
}
pDC->MoveTo(10,10);
pDC->LineTo(200,200);
The same thing happens if the DC is a CMetaFileDC.
The DC seems to be OK, because it works just fine to draw GDI onto that DC.
Is the ID2D1RenderTarget created with incompatible parameters? Should I pass a different pixel format?
Please help.
Thanks.
|
|
|
|
|
D2D does not support rendering to a printer DC. You can render to a WIC bitmat target and then bitblit to the printer DC.
Salvador Patuel
MSFT
|
|
|
|
|
Hi,
Anyone know how to write text to a pdf file using vc++?
Thanks,
|
|
|
|
|
|
|
Or here , or you can use this library , is good one !
|
|
|
|
|
Hi
I need to encrypt the plan text using AES algorithm in java and decrypt the encrypted text using C.Any please give solution ASAP.
Thanks
|
|
|
|
|
Some suggestions:
1. Don't cross post in multiple forums.
2. Don't for the full code ASAP. Members here are not paid to help people, so if you want somebody to provide you with the code ASAP, you'll need to hire somebody.
3. Explain precisely where you are stuck, people here won't provide a fully working solution (for the same reason as point 3).
4. Read the posting guidelines at the top of this message board.
|
|
|
|
|
Is your third point some kind of recursive definition?
|
|
|
|
|
Nice trick there from Cedric!
|
|
|
|
|
Yeah, took me about 15 minutes before I realized I was reading the same row over and over... (cheeky bastard)
|
|
|
|
|
Have a look at OpenSSL. It supports AES and you should be able to use if from Java and C. If you have problems using it from C then feel free to ask questions about how to use it. I believe there's a JNI wrapper for it as well to save you rolling your own but I've never used it.
Oh, and if you do a search for "Gladman" and "AES" you might find another open source implementation of AES. I've never used it but one of my co-workers does in a product. It's lighter weight than OpenSSL and you should be able to compile and link it with your C code.
Cheers,
Ash
|
|
|
|
|
Murugan k wrote: I need to encrypt the plan text using AES algorithm in java and decrypt the encrypted text using C.Any please give solution ASAP.
do you know how to write AES alogorithm in C and Java
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Have a look at Brian Gladman's implementation. That shows you in balls-aching detail how to implement AES. If I were you I'd just use his or the one in OpenSSL.
Cheers,
Ash
|
|
|
|
|
Hi
I am using CClientDc in OnTimer().
Sample Code:
OnTimer()
{
CClientDc dc;
DisplayAll(dc,xCor,Ycor);
Release(&dc);
}
But When run the program through the Deleaker
I am getting GDI leak in this part. I am not sure weather the CClientDc is released. Also my applicatin size increases continously. Pls help to resolve this problem.
|
|
|
|
|
You do not have to call Release .
The destructor of CClientDC will do that when it goes out of scope.
The leak is probably because of something that is happening inside the DisplayAll function.
|
|
|
|
|
«_Superman_» is correct: First lose the Release and see if commenting out DisplayAll stops the leaks. If it does one sledgehammer approach is comment bits of the function out bit by bit until you find the problem.
Steve
|
|
|
|
|
Get rid of all drawing code in your OnTimer. Make sure OnPaint does all the
drawing correctly and then replace all the code in OnTimer with:
Invalidate();
That'll help sort out whether the problem is with the drawing code or whether you're committing another faux pas.
In case you're wondering Invalidate tells Windows that the window you've called it on needs repainting and it should send a WM_PAINT to the app when the message queue is otherwise empty. This WM_PAINT causes OnPaint to be called.
Cheers,
Ash
|
|
|
|
|
Hi All
How can i open Ms PowerPoint password protected file through code?I know password but i haven't idea how to open through code.
Please help me
|
|
|
|
|
|
Hi!
Could you help me please...
I need to save data to file from here:
for (DWORD x = 0; x < pNotification->Count; x++)
{
ASSERT(pNotification->aData[x].Type == JOB_NOTIFY_TYPE);
CJobInfo *pJobInfo = NULL;
if (! m_mapJobInfo.Lookup(pNotification->aData[x].Id, pJobInfo))
{
pJobInfo = new CJobInfo(pNotification->aData[x].Id);
m_mapJobInfo.SetAt(pNotification->aData[x].Id, pJobInfo);
}
ASSERT(pJobInfo != NULL);
pJobInfo->UpdateInfo(&pNotification->aData[x]);
::PostMessage(m_ThreadInfo.GetHwnd(), UDM_UPDATE_JOB_LIST, 0, 0);
}
This is a code of Print monitoring program. Thank you!
|
|
|
|
|
You need to add :
pJobInfo->SaveDataToFile();
After the UpdateInfo() call.
|
|
|
|
|
Rick York wrote: pJobInfo->SaveDataToFile();
nice onE!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello,
Let me first start by telling you I have very little (read: none, ive read some parts in an ebook but..) experience with c++.
I'm trying to manage a callback to a more 'trusted' managed environment.
I'm trying to use SetWindowsHookEx(WH_CBT) on a specified application to monitor and alter window behavior.
I've created the HookProc in unmanaged c++ (see below) together with a Initialize function that takes as argument void* so I can call the function inside my managed application.
I pass the function of my managed application with Managed.getFunctionPointerforDelegate().
This seems to work.
However. If I hook the external process. (Read: Inject all of its threads seperately) it doesn't seem todo the callback to my managed application.
Winapi Override shows my unmanaged dll as being linked. (If I however can't find it through System.Diagnostics.Process.Modules)
The code:
The unmanaged part:
<FONT COLOR="#000099">#include "Hook.h"
</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#FF6633">int</FONT><FONT COLOR="#663300"> (*</FONT>pfnCallback<FONT COLOR="#663300">) (</FONT><FONT COLOR="#FF6633">void</FONT><FONT COLOR="#663300">);</FONT><FONT COLOR="#FF6633">
void</FONT> Initialize<FONT COLOR="#663300">(</FONT>HANDLE retFunc<FONT COLOR="#663300">)
{</FONT><FONT COLOR="#FF0000">
if</FONT><FONT COLOR="#663300"> (</FONT>retFunc<FONT COLOR="#663300"> !=</FONT> INVALID_HANDLE_VALUE<FONT COLOR="#663300">)
{</FONT>
pfnCallback<FONT COLOR="#663300"> = (</FONT><FONT COLOR="#FF6633">int</FONT><FONT COLOR="#663300"> (</FONT>_cdecl<FONT COLOR="#663300"> *) (</FONT><FONT COLOR="#FF6633">void</FONT><FONT COLOR="#663300">))</FONT> retFunc<FONT COLOR="#663300">;</FONT><FONT COLOR="#FF6633">
int</FONT> a<FONT COLOR="#663300"> =</FONT> ThrowMessage<FONT COLOR="#663300">();</FONT><FONT COLOR="#FF0000">
if</FONT><FONT COLOR="#663300"> (</FONT>a<FONT COLOR="#663300">==</FONT><FONT COLOR="#999900">5</FONT><FONT COLOR="#663300">)
{</FONT>
ThrowMessage<FONT COLOR="#663300">();
}</FONT>
ThrowMessage<FONT COLOR="#663300">();
}
}</FONT><FONT COLOR="#FF6633">
int</FONT> ThrowMessage<FONT COLOR="#663300">()
{</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#FF0000"> return</FONT><FONT COLOR="#663300"> (*</FONT>pfnCallback<FONT COLOR="#663300">)();
}</FONT><FONT COLOR="#FF6633">
int</FONT> HookProc<FONT COLOR="#663300">(</FONT><FONT COLOR="#FF6633">int</FONT> nCode<FONT COLOR="#663300">,</FONT> WPARAM wParam<FONT COLOR="#663300">,</FONT> LPARAM lParam<FONT COLOR="#663300">)
{</FONT>
ThrowMessage<FONT COLOR="#663300">();</FONT><FONT COLOR="#FF0000">
return</FONT> CallNextHookEx<FONT COLOR="#663300">(</FONT>NULL<FONT COLOR="#663300">,</FONT>nCode<FONT COLOR="#663300">,</FONT>wParam<FONT COLOR="#663300">,</FONT>lParam<FONT COLOR="#663300">);
}</FONT>
The c# part:
<FONT COLOR="#990000"> public class</FONT> HookManager<FONT COLOR="#663300">
{</FONT><FONT COLOR="#990000">
private</FONT> GCHandle gch<FONT COLOR="#663300">;</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000"> private</FONT> delegate<FONT COLOR="#FF6633"> int</FONT> HookProc<FONT COLOR="#663300">();</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000"> private static</FONT> HookProc hookProc<FONT COLOR="#663300">;</FONT><FONT COLOR="#999999">
</FONT><FONT COLOR="#990000">
private static</FONT> Stack<FONT COLOR="#663300"><</FONT>IntPtr<FONT COLOR="#663300">></FONT> hookList<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> Stack<FONT COLOR="#663300"><</FONT>IntPtr<FONT COLOR="#663300">>();</FONT><FONT COLOR="#990000">
public</FONT> HookManager<FONT COLOR="#663300">()
{</FONT>
hookProc<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> HookProc<FONT COLOR="#663300">(</FONT>HookEvent<FONT COLOR="#663300">);</FONT>
gch<FONT COLOR="#663300"> =</FONT> GCHandle<FONT COLOR="#663300">.</FONT>Alloc<FONT COLOR="#663300">(</FONT>hookProc<FONT COLOR="#663300">,</FONT> GCHandleType<FONT COLOR="#663300">.</FONT>Normal<FONT COLOR="#663300">);</FONT>
IntPtr managedReference<FONT COLOR="#663300"> =</FONT> Marshal<FONT COLOR="#663300">.</FONT>GetFunctionPointerForDelegate<FONT COLOR="#663300">(</FONT>hookProc<FONT COLOR="#663300">);</FONT>
Poseidon<FONT COLOR="#663300">.</FONT>Initialize<FONT COLOR="#663300">(</FONT>managedReference<FONT COLOR="#663300">);
}</FONT><FONT COLOR="#990000">
public</FONT><FONT COLOR="#FF6633"> void</FONT> HookIt<FONT COLOR="#663300">(</FONT>Process hook<FONT COLOR="#663300">)
{</FONT><FONT COLOR="#999999">
</FONT> IntPtr hModule<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>GetModuleHandle<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Poseidon.dll"</FONT><FONT COLOR="#663300">);</FONT>
IntPtr ProcAddress<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>GetProcAddress<FONT COLOR="#663300">(</FONT>hModule<FONT COLOR="#663300">,</FONT><FONT COLOR="#009900"> "HookProc"</FONT><FONT COLOR="#663300">);</FONT>
ProcessThread<FONT COLOR="#663300">[]</FONT> threads<FONT COLOR="#663300"> =</FONT><FONT COLOR="#990000"> new</FONT> ProcessThread<FONT COLOR="#663300">[</FONT>hook<FONT COLOR="#663300">.</FONT>Threads<FONT COLOR="#663300">.</FONT>Count<FONT COLOR="#663300">];</FONT>
hook<FONT COLOR="#663300">.</FONT>Threads<FONT COLOR="#663300">.</FONT>CopyTo<FONT COLOR="#663300">(</FONT>threads<FONT COLOR="#663300">,</FONT><FONT COLOR="#999900"> 0</FONT><FONT COLOR="#663300">);</FONT>
foreach<FONT COLOR="#663300"> (</FONT>ProcessThread thread in threads<FONT COLOR="#663300">)
{</FONT>
IntPtr HHOOK<FONT COLOR="#663300"> =</FONT> Win32<FONT COLOR="#663300">.</FONT>SetWindowsHookEx<FONT COLOR="#663300">(</FONT>Win32<FONT COLOR="#663300">.</FONT>HookType<FONT COLOR="#663300">.</FONT>WH_CBT<FONT COLOR="#663300">,</FONT> ProcAddress<FONT COLOR="#663300">,</FONT> hModule<FONT COLOR="#663300">, (</FONT>uint<FONT COLOR="#663300">)</FONT>thread<FONT COLOR="#663300">.</FONT>Id<FONT COLOR="#663300">);</FONT>
Console<FONT COLOR="#663300">.</FONT>WriteLine<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"{0}, {1}, {2}"</FONT><FONT COLOR="#663300">,</FONT> hModule<FONT COLOR="#663300">,</FONT> ProcAddress<FONT COLOR="#663300">,</FONT> HHOOK<FONT COLOR="#663300">);</FONT>
hookList<FONT COLOR="#663300">.</FONT>Push<FONT COLOR="#663300">(</FONT>HHOOK<FONT COLOR="#663300">);
}
}</FONT><FONT COLOR="#990000">
public</FONT><FONT COLOR="#FF6633"> int</FONT> HookEvent<FONT COLOR="#663300">()
{</FONT>
Console<FONT COLOR="#663300">.</FONT>WriteLine<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Hookevent called!"</FONT><FONT COLOR="#663300">);</FONT><FONT COLOR="#FF0000">
return</FONT><FONT COLOR="#999900"> 5</FONT><FONT COLOR="#663300">;
}</FONT><FONT COLOR="#990000">
private static class</FONT> Poseidon<FONT COLOR="#663300">
{
[</FONT>DllImport<FONT COLOR="#663300">(</FONT><FONT COLOR="#009900">"Poseidon.dll"</FONT><FONT COLOR="#663300">)]</FONT><FONT COLOR="#990000">
public static extern</FONT><FONT COLOR="#FF6633"> void</FONT> Initialize<FONT COLOR="#663300">(</FONT>IntPtr callback<FONT COLOR="#663300">);
}
}</FONT>
Thanks already for reading this far. Does anyone have any idea this is ? Or suggestions?
I desperately try to get this to work. It's driving me nuts right now.
|
|
|
|