|
no its written for VC++.
but i tested the EXE(in release mode) file in Various systems in my office.
|
|
|
|
|
Hi all
I met a confusing issue, just as the title says.
There's a network printer installed in my machine. And in my code when I open this printer with "OpenPrinter" API, it will failed. But, in fact the printer is OK, because I can use it to print in Notepad.
My code is:
HANDLE hPrinter = NULL;
PRINTER_DEFAULTS PDef;
PDef.pDatatype = NULL;
PDef.pDevMode = NULL;
BOOL bRet = OpenPrinter(_T("\\\\172.xx.xxx.xx\\HP LaserJet 1020"), &hPrinter, &PDef);
What confuses me most is that, the "OpenPrinter" API doesn't faill in all test machines. Only in some machines it fails. In most test machines, it is OK to open the printer.
I checked the printer and the test machines, however nothing wrong was found.
And what's more, when OpenPrinter fails, the error code is 5, which means "Access is denied". It seems that the test machines can't access the printer. But it does printing operation OK!
What's the problem with my machine?
Any response will be appreciated very much!
|
|
|
|
|
Unfortunately their are 2 OpenPrinter APIs, one in Winspool.lib and one in SpoolSS.dll. If you use the wrong one then horrible, and not easily predictable, things occur. I suggest you check this out first, determine which one you're calling, try the other one and if things are no better or worse then feel free to vote this a bad answer.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Matthew Faithfull wrote: Unfortunately their are 2 OpenPrinter APIs, one in Winspool.lib and one in SpoolSS.dll. If you use the wrong one then horrible, and not easily predictable, things occur. I suggest you check this out first, determine which one you're calling, try the other one and if things are no better or worse then feel free to vote this a bad answer.
Matthew Faithfull, thank you very much.
I will check it.
|
|
|
|
|
|
Amin, thank you very much!
Actually, I have tested to set the "pDesiredAccess" to "PRINTER_ACCESS_USE", instead of using "PRINTER_ALL_ACCESS". When I doing this, "OpenPrinter" to all printers installed in my machine is successful. However, in fact, there's another network printer which is unaccessible. When I use "PRINTER_ALL_ACCESS" in "OpenPrinter", it can't distinguish this situation.
What I mean is that, in my machine there're two network printers. One is OK and another is really unaccessible. When I use "PRINTER_ALL_ACCESS", "OpenPrinter" to both of the two printers is FAILED. On the contray, use "PRINTER_ACCESS_USE", makes "OpenPrinter" to the two printers successful.
I thought that there should to be a method for "OpenPrinter" to distinguish these two printer accurately. But my test shows that "OpenPrinter" is somewhat awkward.
Maybe there's something wrong with the setting of my computer.
|
|
|
|
|
I am not pretty sure why this happens with the other printer but
you can test by runing your application form some other PC and
check if you can acess both the n/w printers.
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi,
Then i use
STANDARD_RIGHTS_REQUIRED | PRINTER_ACCESS_USE | PRINTER_ACCESS_ADMINISTER everything perfect for network printers.
http://selcukgural.com
|
|
|
|
|
Hi EveryOne,
I am doing one VC++ Program in that i want to insert VB Dll.
i am importing dll in stdafx.h file like this #import "C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll"
In VB Dll i am having one function called ProcessingInformation with 5 string type variables and return type is boolean.
After this i am adding one button in that button function i want access processinformation function but when i am accessing then it is giving error like processinformation is undefined declaration.
Please tell me how to use dll functions in my program i tried but i am getting solution.i used one way which i got from codeproject only but in that midl not found error is coming in command prompt.
Please give me some suggestions...HELP ME OUT...
Thanks in ADVANCE,
Savitri
|
|
|
|
|
For using dll on the c++ you need to use of LoadLibrary and then use of GetProcAddress.
|
|
|
|
|
That's explicit DLL loading. You should mention also the implicit one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I think he wants to load dlls on the c++.
|
|
|
|
|
Hamid. wrote: I think he wants to load dlls on the c++
That's true.
Anyway, you know, there are two ways to do it (and implicit DLL load is the load-time linking with the DLL ).
[added]
Well, maybe I got you: for a VB DLL you haven't neither the .lib nor the the .h file needed to
compiler your project for implicit loading (and I don't remember if #import directive may help).
[/added]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, August 22, 2008 6:40 AM
|
|
|
|
|
Except this, use of windows api's on other languages is difficult c++.
|
|
|
|
|
savitri wrote: I am doing one VC++ Program in that i want to insert VB Dll
The first good question maybe: why do I need such a thing?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hii
Thanks for replying..I am having one DLL in VB for my project Concern.
But i dont how to import DLL's in VC++.When i am doing like that what i mentioned in last message it is not possible to get functions from dll.
So please will you tell me how can i get the functions from the VB dll to vc program.
Please help me out I am trying from two days but i am not getting solution please tell me..I am using loadlibrary and getprocaddress like this:
typedef BOOL (WINAPI* ptr_func1)(BSTR* bstr,BSTR* bstr1,BSTR* bstr2,BSTR* bstr3,BSTR* bstr4);
ptr_func1 ProcessingInformation = NULL;
HINSTANCE hLib;
hLib = LoadLibrary(_T("C:\\Program Files\\Microsoft Visual Studio\\My Projects\\BoolDate\\SampleDll.dll"));
if (hLib == NULL)
{
MessageBox(_T("Unable to load .dll"), NULL, MB_ICONERROR);
}
else
{
ProcessingInformation = (ptr_func1)GetProcAddress(hLib,
_T("ProcessingInformation"));
CString str;
BSTR server,usr,pwd,Temp,Temp3;
BOOL bstr;
Temp=SysAllocString(L"21\8\2008");
str=Temp;
MessageBox(str);
Temp3=SysAllocString(L"21\7\2008");
str=Temp3;
MessageBox(str);
server=SysAllocString(L"savitri");
str=server;
MessageBox(str);
usr=SysAllocString(L"root");
str=usr;
MessageBox(str);
pwd=SysAllocString(L"base");
str=pwd;
MessageBox(str);
/* The actual call to the function contained in the dll */
bstr = ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd);
MessageBox("Gettting BSTR Value");
str.Format("%d",bstr);
MessageBox(str);
SysFreeString(Temp);
SysFreeString(Temp3);
SysFreeString(server);
SysFreeString(usr);
SysFreeString(pwd);
/* Release the Dll */
FreeLibrary(hLib);
}
Please tell me what is wrong with this code.Now i am not getting any errors in compiling time but in run time i am one error message box like send error and don't send..
Please Help me.I need your help very much.
Thanks In Advance,
Savitri
|
|
|
|
|
Does the DLL load successfully?
Also did you check that functions that you are calling are exported from the DLL
BTW on which line do you encounter the crash
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hii
Ya it is loading dll properly because it is not giving error..i am checking conditions also.I send that part of code in last message please tell me what is wrong with my code.I am getting tension.
Please give me some suggetions.please help me out.
Thanks IN ADVANCE,
Savitri
|
|
|
|
|
Hi I just checked by creating ActiveXDLL project in VB.
I don't think you can use it using LoadLibrary().
You have to use
#import "YourDll.dll" no_namespace
Sample Code:
CoInitialize(NULL);
_Class1Ptr class1;
class1.CreateInstance(__uuidof(Class1));
short i=10,k=20;
int ans = class1->add(&i,&k);
class1.Release();
CoUninitialize();
It works properly.
I hope it helps
Regards,
Sandip.
modified on Friday, August 22, 2008 8:11 AM
|
|
|
|
|
Hi Sandip,
I used like this but i am getting errors..I am writting like this:
::CoInitialize(NULL);
//note this change after taking out the no_namespace macro
//if there is no namespace then also the progid has to be __uuidof(VbDll::CVbDll) like this
SampleDll::_FunctionClass sample;
HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll)
//not just CVbDll
//sample.AddRef();
BSTR server,usr,pwd,Temp,Temp3;
BOOL bstr;
Temp=SysAllocString(L"21\8\2008");
str=Temp;
MessageBox(str);
Temp3=SysAllocString(L"21\7\2008");
str=Temp3;
MessageBox(str);
server=SysAllocString(L"savitri");
str=server;
MessageBox(str);
usr=SysAllocString(L"root");
str=usr;
MessageBox(str);
pwd=SysAllocString(L"base");
str=pwd;
MessageBox(str);
BOOL bstrMyString;//=TRUE;
//check for the instance
bstrMyString=sample.ProcessingInformation(&Temp,&Temp3,&server,&usr,&pwd);
str.Format("%d\n", bstrMyString);
MessageBox(str, "MyString aus VB", MB_OK);
sample.Release();
::CoUninitialize();
It is giving errors...
1. C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members: c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass'
2.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(194) : error C2259: '_FunctionClass' : cannot instantiate abstract class due to following members:
c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass'
3.C:\Program Files\Microsoft Visual Studio\My Projects\UseVbDll\UseVbDllDlg.cpp(195) : error C2039: 'CreateInstance' : is not a member of '_FunctionClass'
c:\program files\microsoft visual studio\my projects\usevbdll\debug\sampledll.tlh(34) : see declaration of '_FunctionClass'
My Dll is like this
// c:\program files\microsoft visual studio\my projects\usevbdll\debug\SampleDll.tlh
//
// C++ source equivalent of Win32 type library C:\Program Files\Microsoft Visual Studio\My Projects\BoolDate\SampleDll.dll
// compiler-generated file created 08/22/08 at 17:31:22 - DO NOT EDIT!
#pragma once
#pragma pack(push, 8)
#include <comdef.h>
namespace SampleDll {
struct __declspec(uuid("a3105692-d6d7-41e0-8d8c-f4ab326fa2f4"))
/* dual interface */ _FunctionClass;
struct /* coclass */ FunctionClass;
_COM_SMARTPTR_TYPEDEF(_FunctionClass, __uuidof(_FunctionClass));
// Type library items
struct __declspec(uuid("a3105692-d6d7-41e0-8d8c-f4ab326fa2f4"))
_FunctionClass : IDispatch
{
//
// Wrapper methods for error-handling
//
VARIANT_BOOL ProcessingInformation (
BSTR * Date1,
BSTR * Date2,
BSTR * ServerName,
BSTR * Username,
BSTR * Password );
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall raw_ProcessingInformation (
BSTR * Date1,
BSTR * Date2,
BSTR * ServerName,
BSTR * Username,
BSTR * Password,
VARIANT_BOOL * _arg6 ) = 0;
};
struct __declspec(uuid("650d301c-f7cf-42b5-9075-7faf8bff40ce"))
FunctionClass;
// [ default ] interface _FunctionClass
#include "c:\program files\microsoft visual studio\my projects\usevbdll\debug\SampleDll.tli"
} // namespace SampleDll
#pragma pack(pop)
Help me out.
Thanks,
Savitri
|
|
|
|
|
savitri wrote: HRESULT hr=sample.CreateInstance(__uuidof(SampleDll::_FunctionClass)); //here the progid is VbDll::CVbDll)
Dont pass _FunctinClass
use SampleDll::FunctionClass.
Also You are using
SampleDll::_FunctionClass sample;
Here you need use
SampleDll::_FunctionClassPtr sample;
Just check my post again.
BTW
Use Code block button below posting area for code blocks it is very difficult to read your code otherwise.
Regards,
Sandip.
modified on Friday, August 22, 2008 8:17 AM
|
|
|
|
|
Hii
I did as u told but no change in it..i am fed of this dll..
thanks for response,
savitri
|
|
|
|
|
I don't know it should work
All the best
Regards,
Sandip.
|
|
|
|
|
Did you try to debug? At what line the error occurs? Do you have the source of the VB DLL ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hii
I am getting error when the cursor is on the function called..ya i am having vb Dll code of 5 line..it is test dll..so i am testing whether vb dll can i insert properly or not in vc program.please tell me how come out from this problem.
Please give me some suggetions.please help me out.
Thanks IN ADVANCE,
Savitri
|
|
|
|
|