473,563 Members | 2,517 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access violation writing error

4 New Member
I am getting the following error from my code:

Traceback (most recent call last):
File "<pyshell#309>" , line 1, in <module>
get_handles('Py thon26')
File "C:\Python26\e_ _handle.py", line 19, in get_handles
ctypes.windll.u ser32.EnumWindo ws(ctypes.c_lon g(function),cty pes.byref(ctype s.c_char_p(arg) ))
WindowsError: exception: access violation writing 0x0064BCF6

From some searching online I think it's because I'm not able to properly pass the function's address pointer.
Expand|Select|Wrap|Line Numbers
  1. from e__handle import EnumWindowsProc, EnumChildWindowsProc
  2. import ctypes
  3. global listed
  4. global parents
  5. listed=[]
  6.  
  7. arg=str(parent_search_text)+'|'+str(parent_case_sensitive)+'|'+str(document)+'|'+str(child_search_text)+'|'+str(child_case_sensitive)+'|'+str(get_children)+'|'+str(id(EnumChildWindowsProc))
  8. function=id(EnumWindowsProc)
  9.  
  10. ctypes.windll.user32.EnumWindows(ctypes.c_long(function),ctypes.byref(ctypes.c_char_p(arg)))
  11. if document==True:
  12.     return listed
  13. else:
  14.     listed=[]
So the jist of the code is that I have defined EnumWindowsProc further down. I import the function so now it should be associated with an memory location. I use id(EnumWindowsP roc) to get the address, but when I try to make it a pointer the pointer ends up referencing the location of the integer and not the function. Please let me know if this isn't clear.

I changed the one line to
ctypes.windll.u ser32.EnumWindo ws(ctypes.POINT ER(function),ct ypes.byref(ctyp es.c_char_p(arg )))

and got a different error of:
Traceback (most recent call last):
File "<pyshell#311>" , line 1, in <module>
get_handles('Py thon26')
File "C:\Python26\e_ _handle.py", line 17, in get_handles
ctypes.windll.u ser32.EnumWindo ws(ctypes.POINT ER(function),ct ypes.byref(ctyp es.c_char_p(arg )))
TypeError: must be a ctypes type

Any ideas?
Aug 14 '09 #1
3 8380
amungen
4 New Member
I was able to use ctypes.pointer instead of ctypes.POINTER for the following:
ctypes.pointer( ctypes.c_int(id (function name)))

However, now I'm getting a different error that gets triggered on the line that calls the EnumWindows function

Expand|Select|Wrap|Line Numbers
  1. from e__handle import EnumWindowsProc, EnumChildWindowsProc
  2. import ctypes
  3. global listed
  4. global parents
  5. listed=[]
  6. arg=str(parent_search_text)+'|'+str(parent_case_sensitive)+'|'+str(document)+'|'+str(child_search_text)+'|'+str(child_case_sensitive)+'|'+str(get_children)+'|'+str(id(EnumChildWindowsProc))
  7. function_pntr=ctypes.pointer(ctypes.c_long(id(EnumWindowsProc)))
  8. ctypes.windll.user32.EnumWindows(function_pntr,ctypes.byref(ctypes.c_char_p(arg)))
  9. if document==True:
  10.     return listed
  11. else:
  12.     listed=[]
Traceback (most recent call last):
File "<pyshell#1 >", line 1, in <module>
get_handles('Py thon26')
File "C:\Python26\e_ _handle.py", line 17, in get_handles
ctypes.windll.u ser32.EnumWindo ws(function_pnt r,ctypes.byref( ctypes.c_char_p (arg)))
WindowsError: exception: access violation writing 0x006917E0

I have also received the following error after restarting the Python Shell:

Traceback (most recent call last):
File "<pyshell#5 >", line 1, in <module>
get_handles('Py thon26')
File "C:\Python26\e_ _handle.py", line 18, in get_handles
ctypes.windll.u ser32.EnumWindo ws(function_pnt r,ctypes.c_char _p(arg))
WindowsError: exception code 0xc000001e

but then it went back to the first error.

Is there a way of determining if I'm not calling the EnumWindows function correctly?
Aug 14 '09 #2
amungen
4 New Member
Okay, so it turns out that I was not using the correct type to pass to the function. I ended up using:

function_ptr=WI NFUNCTYPE(c_int ,c_int,c_int)
then calling the EnumWindows function like this:
ctypes.windll.u ser32.EnumWindo ws(function_ptr (function name),argument)

(a good example can be found at http://bytes.com/topic/python/answer...og-box-removal)

The above code now correctly calls the function, however, there is still something I need help with...

I am attempting to pass a string through the EnumWindows function call to my defined function. The problem I'm having is that all that shows up to my user defined function is an integer. I'm thinking it's because it's passing a reference or pointer to the variable instead of the value itself.

Is there a ctypes function or method that I haven't found yet that will take the pointer value and allow me to attach it to a ctypes object (like c_char_p, which is how it is being sent)?
Aug 15 '09 #3
amungen
4 New Member
I think I will mark this particular thread as being solved and start a new thread for the new issue I need help with.
Aug 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
17996
by: Steven Reddie | last post by:
I understand that access violations aren't part of the standard C++ exception handling support. On Windows, a particular MSVC compiler option enables Microsoft's Structured Exception Handling (SEH) in C++ EH so that a catch (...) will catch an access violation. I don't know if other platforms support something similar. I'm wondering about...
11
4175
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And I don't know where the problem lies in the code. Can anyone run it through there own compiler please and tell me where and what the problem is. ...
0
2710
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access violations aren't part of the standard C++ >> exception handling support. On Windows, a particular MSVC compiler >> option enables Microsoft's...
0
1802
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a TabControl to my form and placed a
1
2310
by: Yanping Zhang | last post by:
Here are more details about my codes, please help! The function declared in C: typedef void (WINAPI *PLEARNCALLBACKPROC) (unsigned int progress, unsigned int sigQuality, unsigned long carrierFreq, void *userData); UUIRTDRV_API BOOL PASCAL UUIRTLearnIR(HUUHANDLE hHandle, int codeFormat, char *IRCode, PLEARNCALLBACKPROC progressProc, void...
1
13890
by: =?Utf-8?B?c2F0aGVlc2t1bWFy?= | last post by:
In my project i have a component named PTS Engine which is developed in VC++ ..Net 2003. And it is migrated to VC++.NET 2005 version. Initially this migration process has coded and tested in VC++ .NET 2005 Beta version. In beta version everything is working fine. When i tryied to run in .NET 2005 full version i am facing the following access...
2
4265
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the win32 CreateEvent() call: Code Snippet static HANDLE hReadyEvent;
39
4243
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it just now, I am getting the subject error message (specifically: PHP has encountered an access violation at 00F76E21). The error is NOT occurring...
0
2259
by: trayres | last post by:
Hi all! I'm trying to use ctypes to access a function in a DLL. Here is the function prototype: extern "C" void__stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); Here is the python code. It is really simple: I initialize each of the variables, then make a pointer to them. Python code: FROGPCGPMonitorDLL =...
0
7877
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6238
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2077
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
912
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.